Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Replacing parts of a string

by spiderbo (Sexton)
on Apr 15, 2003 at 08:23 UTC ( [id://250502]=note: print w/replies, xml ) Need Help??


in reply to Re: Replacing parts of a string
in thread Replacing parts of a string

silly question, however I know it will take you seconds to answer and me hours to find, but, how do you get the bit which you strippped when you did:

$str =~ s/^[^\?]+\?//;

i.e. I am looking for 'calendarview.pl'

Thank you.

Replies are listed 'Best First'.
Re: Re: Re: Replacing parts of a string
by tachyon (Chancellor) on Apr 16, 2003 at 03:15 UTC

    You can capture into $1, $2, $etc using parens around (what you want) in a regex. If there are multiple parens then you get the first capture in $1, next in $2, etc

    $str = 'http://somesite.com/cgi-bin/calendar.pl?some=qstring'; # the typical perlish idiom looks like this # we are capturing $1 and $2 and assigning them to vars # all in one line (note this uses m//) my ( $site, $q_string ) = $str =~ m/^([^\?]+)\?(.*)$/; print "site: $site\nq string: $q_string\n"; # simple way, just modifying the s/// we had $str =~ s/^([^\?]+)\?//; my $capture = $1; print $capture; # $str now contains q string

    Details see perlre

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://250502]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-18 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found