rrlobster has asked for the wisdom of the Perl Monks concerning the following question:

I know nothing about Perl so I'm really seeking wisdom here. (sorry if duplicate post -- first time wasn't logged in but can't find so reposting.)

I want to modify this line:

# Erase the leading spaces and parenthetical values. #for (@t){s/^ +//;s/\(\)//g};

so that for each line in the array, it also truncates all text from " / " (space-slash-space) to the end of the line.

In other words the line:
Windchill 17º F / -8º C
should become
Windchill 17º F
My stab in the dark was this:
for (@t){s/^ +//;s/\(\)//g;s/^\([^\ \/\ ]*\)\ \/\ .*/\1/p};
But I obviously do not know what I'm doing -- I know some basic Regex and Unix but not Perl...

Thanks for your indulgence.

Replies are listed 'Best First'.
Re: truncate line starting with multi-char delimiter
by ikegami (Patriarch) on Jan 10, 2010 at 17:08 UTC
    Remove spaces followed by a slash followed by anything.
    for (@t) { s/^ +//; s/\(\)//g; s/\s*\/.*//; }
      perfect, thanks!