Closed Thread Icon

Topic awaiting preservation: Replacing and filtering scalars in Perl (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12278" title="Pages that link to Topic awaiting preservation: Replacing and filtering scalars in Perl (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Replacing and filtering scalars in Perl <span class="small">(Page 1 of 1)</span>\

 
Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 06-21-2002 12:21

How do all those nifty shorthand find-n-replace and filtering lines in Perl?

ex:
$onlyindexes =~ /^index\.html$/i
(or something..)


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

rickindy
Nervous Wreck (II) Inmate

From: Indianapolis, In USA
Insane since: Jan 2002

posted posted 06-21-2002 13:55

Regular expressions are on of Perl's many cool tools. Here's a good tutorial that's easy to understand:
http://www.itworld.com/nl/perl/12072000/

HTH


Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 06-21-2002 15:45

oo.. neat-o keen! things got a lot easier when I figured out that they were called regexes..

so... um..... how do I go about replacing that expression?


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-21-2002 16:48

what to you mean by replace?

You want to replace everything that matches that with something else?

usually its

$variable =~ s/expression to check for/expresion to replace with/gieo

Where s means substitute gieo are all optional g means global i means case insensitive e indicates an expression o is the oppisite of g basically meaning only replace the first match.

ooh and a great tip especailly for when you are parsing things like directory names. the "/" can actually be any character so you could write it s#expr#replace#g if you don't want to worry about escaping all the slashes in things like directory paths.



.:[ Never resist a perfect moment ]:.

[This message has been edited by bitdamaged (edited 06-21-2002).]

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 06-21-2002 16:49

oh, I see...

using 's/' instead of 'm/'

hey, this link is really cool.. http://www.wdvl.com/Authoring/Languages/Perl/PerlfortheWeb/pattern_matching.html


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

hlaford
Bipolar (III) Inmate

From: USA! USA! USA!
Insane since: Oct 2001

posted posted 06-21-2002 20:19

The /o flag actually causes the regular expression containing variables to be compiled only once.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 06-21-2002 21:37

/g is usually the only flag I use.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-22-2002 02:34

whoops my bad like Slime I mostly only use g and i.




.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu