![]() |
Counting a single character in a string
I have a list of a directory and need to process the files depending on the number of underscore characters in the file name. For example, the files
filename_date.txtwill be processed differently by the script. I've tried $count = ($data =~ tr/_/_/); but it doesn't seem to work - I continue to get a zero (0) for $count. Is there a flaw in my logic above? Is there a better way to do this? Thanks in advance! Tom |
You might post the other code that deals with the $count var. The example you posted looks correct.
|
This works for me:
:
#!/usr/bin/perlAs an alternative, I wrote a small function also... :
|
Thanks to both of you. Turns out that the value I was moving to $data was wrong ... should have checked that before posting I guess ... just too many things happening at once and too many 'break/fixes' on my plate.
Appreciate it! Best, Tom |
| All times are GMT -5. The time now is 12:44 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC