perl string match issue
Hi every one,
Code:
#!/usr/bin/perl Code:
five See "two" should print "match found" but it doesn't. Any ideas? Thanks |
You left out two ending brackets when you pasted your code btw. :)
If you put a Code:
print "Length of test is " . length($test) . "\n"; Code:
chomp($test); |
That's because the lines from the file have a newline at the end, whereas the ones in your array do not. Use chomp to remove it:
Code:
#!/usr/bin/perl -w "five " "one" "five " "two" "perlmonks" is a good and very active forum for perl help. ps. why did you use c-style comments? |
Quote:
I love playing on hardware level with C. Its awesome |
Thank you very much both of you,
mk27 thanks for pointing out loop thingie. |
Good time to ask an old question
Code:
my @names=qw( one two three four ); # no need to redeclare this each time in the loop! Thanks |
Quote:
|
@knockout-artist; ALL perl programs should start with
Code:
#!/usr/bin/perl -w An alternative to '-w' is 'use warnings;' Also, if you want to do a test compile without running the prog, use perl -wc prog.pl If you 'use strict;' then you have to declare your vars using 'my', which restricts their scope to the current block (usually current subroutine). IOW, avoid globals as much as possible. Think C (also my main lang prev to Perl). :) Good Perl links: http://perldoc.perl.org/ http://www.perlmonks.org/?node=Tutorials |
Code:
What I need is out put [qoute]one three[/quote] what I get is Quote:
output :: Code:
./last-log2.pl Any ideas? Thanks! |
BTW
I was able to resolve it. I will post the code tomorrow. Thank you every one. :-) |
Don't forget the -w switch (or 'use warnings').
I'd also change while(<DATA>) to while( defined($test = <DATA>) ) removing need for my $test=$_; Try indenting your code as well, its easier to read... |
Seconded on warnings & strict.
My Perl places will tell you to put those in and run your code again before bothering to help... although I don't think they would've helped here. |
All times are GMT -5. The time now is 09:25 AM. |