(-1 so that split wouldn't remove trailing newlines, if any)my @lines = split /\n/, $header, -1;
Then I would find the needed line in @lines and substitute stuff like this:
I guess not many people know that substr is magic (and so is foreach loop)... but it works. It's straight from the documentation, so it can't be too bad :) tr works with empty searchlist and "c"omplement option, I don't know why, it's probably better written like this: tr/\x00-\xff/ /for my $magic_part ( substr $needed_line, 23 ) { die "Line is too short!" if length $magic_part < 5; $magic_part =~ tr// /c; # double magic :) substr( $magic_part, 0, 5 ) = "sun4v"; }
Then I would join the array with newlines again and overwrite the whole header. Yes, pretty obscure stuff here, but I'm very bad at math. I try to avoid it as much as I can :)my $line = "x" x 23 . "something"; for my $magic ( substr $line, 23 ) { print length $magic, "\n"; $magic =~ tr/\x00-\xff/ /; substr( $magic, 0, 5 ) = "sun4v"; } print "~~$line~~", "\n" __END__ 9 ~~xxxxxxxxxxxxxxxxxxxxxxxsun4v ~~
In reply to Re: In place editing without reading further
by Anonymous Monk
in thread In place editing without reading further
by trippledubs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |