Need help parsing

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone,
Sorry I'm kind of a noob.

I have the following string:


and I need to parse out the word jimmy. So I tried:

$string=~ m/$printdir\/(.*)\/(.*)/o;

print "$1, $2";

thinking it would output:

jimmy, iadj41508b/1

but it outputs:

jimmy/iadj41508b, 1

So it thinks the last slash is the one I'm interested in. So the
$printdir is always the same but after that it changes and it can be
deeper or less deep that the sample line above.
Can anyone help me with this? Thanks.

Oh, I need the stuff after Jimmy to go to another variable ideally.

Re: Need help parsing

Quoted text here. Click to load it
That can match slash characters...

Quoted text here. Click to load it

Write your pattern so that the part you do not want to match slash
characters cannot match slash characters.

(And use an alternate delimiter to avoid backslash clutter):


Quoted text here. Click to load it

    my($another_variable) = $string=~ m#$printdir/[^/]*/(.*)#o;

Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Site Timeline