in reply to Re^2: Array of strings search
in thread Array of strings search
split is aimed at splitting a string into a list of parts, in order to later use these parts. Usually, the first parameter of split is the separator on which you want to break up the string (although the separator can be a bit more complicated than a simple character). You could certainly use split on your problem (as a part of the solution), it is probably not the best tool for your task. A simple regex is probably better.
One possible way to get the sender:
This captures a string of as many characters other than spaces as possible following the "sender=" string in the $_ variable.my $sender = $1 if /sender=(\S+)/;
Update: I have never actually seen any problem with this syntax, but I have read several times and AnomalousMonk reminds me that conditionally defining lexicals can lead to unexpected results. Perhaps it is better to write:
or possibly:my $sender; $sender = $1 if /sender=(\S+)/; if (defined $sender) { # ...
Thanks, AnomalousMonk.if (/sender=(\S+)/) { my $sender = $1; do_something_with_sender(); }
|
|---|