in reply to Building Paths without Regex

Be aware that regular expressions are case sensitive; you are looking for "foo" but the string contains "FOO". Also, you seem to be matching against $_ and applying substr to it but your code doesn't show where you initialise it. I'm finding your question a little difficult to understand but perhaps captures and lc would be applicable.

knoppix@Microknoppix:~$ perl -Mstrict -wE ' > my $var1 = q{some_stuff_FOO}; > my $var2 = q{more_gubbins_BAR}; > my $var3 = q{lose_this_LOST}; > > my $path = join q{/}, > q{}, > map { my( $ext ) = m{([A-Z]+)$}; lc $ext } $var1, $var2, $var3; > say $path;' /foo/bar/lost knoppix@Microknoppix:~$

I hope I've guessed correctly and this is helpful.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Building Paths without Regex
by rehann (Initiate) on Sep 01, 2011 at 19:18 UTC

    Thank you for the quick answer! I found a typo in the first if statment while I was ensuring that I was doing everything case sensitive. Here is an example of what I was doin wrong:

    if (/bar/){ $foo = substr($_, 5) } elsif (/bar/) { $bar = substr($_, 8) }

    I was testing for /bar/ but adding the variable to $foo, which was messing up the first variable $var1. To answer your question, the $_ is the default value from the while loop used to read the source file. I want to apologize for not making my post clearer. I am reading data from a file using a while loop. I've been at this for 12 hours straight :) and am a little fried