Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: Problem with ampersand and regex

by Anonymous Monk
on Dec 19, 2012 at 20:46 UTC ( #1009633=note: print w/replies, xml ) Need Help??

in reply to Re: Problem with ampersand and regex
in thread Problem with ampersand and regex

You are correct and thank you for pointing that out. Unfortunately, I am still having problems though. In an attempt to make the post easy to read, I left out some of the code and that makes the answer thus far impossible as far as I can see. Here is how my code should have looked:
foreach my $line (@array) { if ($line =~ /mail: /) { my $mail = substr($line, $+[$#+] ); print "mail=$mail\n"; } }
With that, I see no way to use the single quotes as suggested. Any other possible solutions??

Thank you again.

Replies are listed 'Best First'.
Re^3: Problem with ampersand and regex
by davido (Archbishop) on Dec 19, 2012 at 21:11 UTC

    What do you get if you capture?

    if( $line =~ /^mail:\s+([\S]+)$/ ) { my $mail = $1; print "mail=$mail\n"; }


      I get ? ?

        Add the following to your script:

        use Data::Dumper;

        ...and then on the line immediately preceding your "for" loop, add, "print Dumper \@array;".

        There might be something broken in your input data, and that would be a simple means of identifying (or eliminating) it as a problem.


Re^3: Problem with ampersand and regex
by roboticus (Chancellor) on Dec 19, 2012 at 22:25 UTC

    The '@' isn't a problem when you read it from a file. Only if you're using it in a double-quoted string. For example:

    $ cat #!/usr/bin/perl use strict; use warnings; my @array = <DATA>; foreach my $line (@array) { if ($line =~ /mail: /) { my $mail = substr($line, $+[$#+] ); print "mail=$mail\n"; } } __DATA__ This @ should be just fine mail: this @ should also be fine $ perl mail=this @ should also be fine


    When your only tool is a hammer, all problems look like your thumb.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009633]
[LanX]: :)
[LanX]: Yesterday I made B::Concise produce a nested AoH of the optree instead of text
LanX chacka!!!
[LanX]: whats the correct way to make a perlbug report for perldoc?
[erix]: chacka
[LanX]: with a diff? which perldoc version should I take from where?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-04-24 15:15 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.