Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^2: Search and Replace Elements from 1 array to another.

by skp (Initiate)
on Apr 03, 2012 at 14:58 UTC ( #963259=note: print w/replies, xml ) Need Help??

in reply to Re: Search and Replace Elements from 1 array to another.
in thread Search and Replace Elements from 1 array to another.

Thanks! That is what I was looking for. One addition needed is that if a match was found it would replace the match along with the rest of the pre split element if possible.

Apologies for not wording that better.

Current output $VAR1 = 'nbu103 Disk 6 -1'; $VAR2 = 'nbu104 Disk 6 -1'; $VAR3 = '204_tape 1 1 ACS1'; $VAR4 = 'nbu101 Disk 6 -1'; Needed output $VAR1 = '103_dsu 1 35 nbu103 Disk 6 -1'; $VAR2 = '104_dsu 1 35 nbu104 Disk 6 -1'; $VAR3 = '204_tape 1 1 ACS1'; $VAR4 = '101_dsu 1 35 nbu101 Disk 6 -1';

Replies are listed 'Best First'.
Re^3: Search and Replace Elements from 1 array to another.
by Riales (Hermit) on Apr 03, 2012 at 17:46 UTC

    Shouldn't be much of a change. The only somewhat tricky part might be a fancier use of split in order to avoid having to concatenate the first few values together after splitting them previously. I think this should work:

    # Instead of the existing split in the code I wrote... my ($pre, $possible) = split / ([^ ]+)$/, $stu;

    That way, you can just concatenate $pre to the beginning of $matched_dp when you assign to $stu.

    As a sidenote, am I the only one that was surprised to find that Perl does not have an rsplit function? This is possibly the first time I've found myself thinking 'Gee, if this were Python...' :P

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://963259]
[Your Mother]: Stick with what you know. Or post a SOPW and if it's not complicated I guarantee someone will answer; me if it's straightforward and no one else gets it better first.
[1nickt]: ++YourMother (Grammar Vigilante of Bristol)
[Lady_Aleena]: Um, how does grep do multiline? print "$file:$_" if grep { /get_(array|hash| data)\(.+\)/ } $_; only returns the same 18 lines the command line grep does.
[Lady_Aleena]: my scratchpad has what I have so far.
[choroba]: what do you mean by multiline?
[Discipulus]: thanks 1nickt!
[choroba]: grep is a filter, it selects elements from a list based on a boolean condition
[moritz]: you need to read the file in one go to do a multiline regex match
[erix]: ha ha, I like the Vigilante
[Lady_Aleena]: Forget it. I'm getting angry with it.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-05-23 19:51 GMT
Find Nodes?
    Voting Booth?