Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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]
[Corion]: Hmm - actually, I don't need them, even though they'd be nice. I just want the (say) 10 latest images, and that's easily done with a limit 10 offset 0 clause, as I don't need all top 10 images for all users.
[Corion]: erix: Sure, but this is for a really-lightweight application and I'm replacing a CSV file / JSON file for user configuration with SQLite (and optionally, Pg) :)
[erix]: isn't a texty format handier for configs?
[Corion]: So far, I've avoided having even a user database by storing the user information in a (signed) cookie that the browser keeps for me, but as I want to be able to lock users, I need a second storage option :)
[Corion]: erix: It's needed for keeping the list of users and the list of tags associated with an image, and for keeping the images with users. I want an easy way to know if an image can be deleted, which means that it can't be referenced by any tag anymore. ...
[Corion]: SQL feels like a natural choice here :)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2018-03-20 14:06 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (253 votes). Check out past polls.