Perl Question
Everyone loves perl right?
I am trying to learn some perl, so i am using it to parse email (Net::Pop3) everything is fine, but i cannot figure out how to grab a line with something something instead of something else so if i have Code:
if($line =~ m/^something (.*)/){ something something ? Thanks in advance! |
What exactly is the line your'e trying to match? By "something something", do you mean you want to match a string, then whitespace, then the repeated string? If you're trying to match an email address, do
Code:
m/^\S+@\S+\.\S+$/i Also, why did you set $variable to 1 and then do a 500-character substring on it? Best, Alek |
Sorry I was not clear.
I need distinguish between something something and something else I did that bc that was the example i found. :confused: (set it to 1) basically i just need to find out how to match a string with a space between the words. |
example code, example data
|
Quote:
Code:
m/^something ([\w]+)/ So the following code: Code:
$line = "something else"; Hope this helps. |
Thanks!
ive gotten this to do everything i need, except for 1 thing. how do i grab 5 line? like if i just want to get the first 5 lines under the one i am matching, how do i do this? currently: Code:
elsif( $line =~ m/^\s+\Wdate\W (.*)/) |
how about?
Code:
($one, $two, $three, $four, $five) = <STDIN>; are discarded. May not be what you want? EDIT: This is not a good solution. |
This is better,
Code:
for $i (1..5) { |
thanks!
i think i need to read more about the <STDIN> to understand this, i spent a few hours yesterday learning Code:
.. |
it's easy
$thing = <STDIN> reads a line @thing = <STDIN> slurps up the lot. of course true for any normal filehandle |
An update:
I got everything working the way i wanted. Thanks again for the help. Perl just keeps getting sweeter and sweeter |
Another small issue:
Code:
if($blob =~ m/Front(.*?)Back\n/) { thanks |
maybe try the s modifier (man perlre for more infos)
Code:
$reqt = $1 if $s =~ /Front(.*)Back\n/s; |
Code:
#!/usr/bin/perl -wn Code:
billym.>cat 1 I have used the -n switch here for the sed-like implicit loop, just for terse-ness (?) in my example. Hence the BEGIN block (otherwise it would undef the $\ for each line) |
Thanks to both, i added the "s" like above and it worked, i will be checking this example today though.
|
All times are GMT -5. The time now is 04:18 PM. |