Home > Archive > PERL Programming > August 2006 > Strange Perl output
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Strange Perl output
|
|
| tommy.geerts@gmail.com 2006-08-16, 7:57 am |
| Hi ,
I am running this script
#!/usr/local/bin/perl
#
$day =`cat /tmp/currentape | grep "Media Label"`; # Cats the file and
searches it for Monday
if ($day = ~m/ MON /ix){ #if the day contains monday
print "Mondays tape\n $day\n"; #print it is mondays tape
} else {
print "Some other days tape\n"; #if the file does not conatin the label
monday, print some other days tape
}
But the output is :
> ./tapetest.sh
Mondays tape
4294967295
! first issue is its not the moday tape cause when i do the cat
/tmp/currentape | grep "Media Label" the output contains no MON
!! second is that the output of variable $day is in numbers ??
what am i doing wrong.. Thanks !
| |
| Sherm Pendley 2006-08-16, 7:57 am |
| tommy.geerts@gmail.com writes:
> I am running this script
>
> #!/usr/local/bin/perl
> #
> $day =`cat /tmp/currentape | grep "Media Label"`; # Cats the file and
> searches it for Monday
> if ($day = ~m/ MON /ix){ #if the day contains monday
^^^
You've misplaced a space here. The result is that the = and ~ are taken as
two separate operators, as if you'd written this:
if ($day = ~($_ =~ m/ MON /ix)) { # do stuff...
}
The above takes the return value of the match, performs a bitwise complement
on it, then assigns the result to $day.
What you *meant* to write is this:
if ($day =~ m/ MON /ix) { # do stuff
}
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
| |
| tommy.geerts@gmail.com 2006-08-17, 7:57 am |
|
Sherm Pendley wrote:
> tommy.geerts@gmail.com writes:
>
> ^^^
>
> You've misplaced a space here. The result is that the = and ~ are taken as
> two separate operators, as if you'd written this:
>
> if ($day = ~($_ =~ m/ MON /ix)) { # do stuff...
> }
>
> The above takes the return value of the match, performs a bitwise complement
> on it, then assigns the result to $day.
>
> What you *meant* to write is this:
>
> if ($day =~ m/ MON /ix) { # do stuff
> }
>
> sherm--
>
Thanks sherm !
|
|
|
|
|