Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

BBS: Re: Perl string manipulation - September 18, 1998 at 07:33:33

You are here: irt.org | BBS | Re: Perl string manipulation [This BBS is closed]

Posted by Jason Nugent on September 18, 1998 at 07:33:33:

In Reply to: Re: Perl string manipulation posted by Jason Turner on September 18, 1998 at 03:32:52:

:
: : : I have a perl variable that contains this text
: : : |password | +----------+ |rangers |
: : : (Password is the column name, rangers the data).
: : : Can anyone suggest how to extract the 'rangers' part of the string?

: #! /usr/bin/perl -w
: for $i ('foo ','bar','H!LL ','pa$$ ','di da ',' ','') {
: $data = "|password | +------+ |$i|";
: print "\nData is now :",$data,":\n";

: @new = ( 0 .. 9 ); # initialise array with some numbers

: $new[0] = pop @{ [ split '\|' => $data ] };
: ($new[1]) = reverse split '\|' => $data;
: $new[2] = $1 if ($data =~ /\| ([^|]+)\|$/);
: $new[3] = (split '\|', $data)[3];
: $data =~ /\| ([^|]*)\|$/ ; $new[4] = $1;
: ($new[5] = $data) =~ s/.*\| ([^|]*)\|$/$1/;
: $new[6] = (split '\|' => $data, -1)[-2];
: $new[7] = (reverse split '\|' => $data, -1)[1];
: $new[8] = (split '\|', $data, -1)[3];
: chop ($new[9] = pop @{[split '\|' => $data, 4]});
: { local $, = ":" ; print "Results ",@new,"\n" }
: }
: __END__

Bloody obfuscated mess :) I love it.

Jason

Follow-ups:

You are here: irt.org | BBS | Re: Perl string manipulation [This BBS is closed]

©2018 Martin Webb