Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Removing data from a string with Regex

by jwest (Friar)
on Nov 15, 2001 at 02:14 UTC ( #125441=note: print w/replies, xml ) Need Help??

in reply to Removing data from a string with Regex

Instead of using substitution, you might try something like this:

$from =~ /^([^@]+)@/; $from = $1;

The first line will take all the characters starting from the beginning of $from that aren't '@' and capture them to the special variable $1. Then, reassign $from to the value of $1.

To do this with substitution, you could try:

$from =~ s/@.*//;
which would substitute the '@' and anything that followed with nothing.

Hope this helps!


-><- -><- -><- -><- -><-
All things are Perfect
    To every last Flaw
    And bound in accord
         With Eris's Law
 - HBT; The Book of Advice, 1:7

Replies are listed 'Best First'.
Re: Re: Removing data from a string with Regex
by pike (Monk) on Nov 15, 2001 at 13:46 UTC
    Taking this approach one step further, the original loop could be simplified to:

    while (<FILE>) { my ($name) = /^--from\s*([^@]+)/; print ($name) if defined $name; }


      That regex would allow --from to pass and assign ' ' to $name. It would likely be better to use:/^--from\s*([^@\s]+)/ which fails for --from and could simplify the code further.

      while ( <FILE> ) { print $1 if /^--from\s*([^@\s]+)/; } or: print $1 if /^--from\s*([^@\s]+)/ while <FILE>;

      Charles K. Clarkson

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://125441]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-02-21 22:28 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (288 votes). Check out past polls.