in reply to regexp to return rest of string

Or in one line:
$relative_url = ($string =~ /content(.*)/, $1)[1];
Thanks to Joe Hall's Effective Perl Programming. Thanks plaid.

Replies are listed 'Best First'.
RE: Re: regexp to return rest of string
by BBQ (Curate) on Jun 03, 2000 at 01:27 UTC
    Humm... I seriously don't get it. And I don't mean to sound rude, but you're saying that you can reduce the two regex lines to one regex/ary line, but you can't figure out the regex itself? I'd have more trouble getting through the reduction than doing that simple regex. It just sounds fishy.

    Is this a case of knowing a previous language before perl, or something of the sort?

    That was a cool trick, btw.

    #!/home/bbq/bin/perl
    # Trust no1!
      I figured out this trick (or actually a variant) just by lots of trial and error with regexs in my early perl days. I prefer using parentheses rather than array subscripts, eg:

      ($relative_url) = ($string =~ /content(.*)/);

      A _very_ useful version of this trick is with DBI, ie:

      $getStuff = $dbh->prepare("select id, price, info from mytable");
      $getStuff->execute();
      ($id, $price, $info) = $getStuff->fetchrow_array();
      I use this a ton.

      -- Kirby

      Tuxtops: Laptops with Linux!