Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: matching substring in url

by roboticus (Chancellor)
on Nov 09, 2019 at 19:11 UTC ( [id://11108517]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    echo "$XXX" | perl -pe '$_=(split "/", (split ";")[0])[-1]'
  2. or download this
    my $url = "/bla/bla/123;yarg";
    my @tmp = split ";", $url;    # break string at semicolons
    @tmp = split "/", $tmp[0];    # break first chunk apart at "/"
    print $tmp[-1];               # Print the value we want
    
  3. or download this
    my $url = "/bla/bla/123;yarg";
    
    ...
    
    # The last item holds the value we want
    print $tmp[-1];
    
  4. or download this
    my $url = "/bla/bla/123;yarg";
    
    $url = (split "/", (split ";", $url)[0])[-1];
    
    print $url;
    
  5. or download this
    perl -e '$a="/bla/bla/123;yarg"; print (split "/", (split ";", $a)[0])
    +[-1]'
    print (...)_ interpreted as function at -e line 1.
    syntax error at -e line 1, near ")["
    execution of -e aborted due to compilation errors.
    
  6. or download this
    perl -e '$a="/bla/bla/123;yarg"; print +(split "/", (split ";", $a)[0]
    +)[-1]'
    123
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108517]
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-03-29 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found