in reply to How do I escape a :: in s///?
Actually you should use File::Tie module. It is a better module to use. Try to avoid running shell commands if you can.
#!/usr/bin/perl use warnings; use strict; use Tie::File; use File::Copy; use Sys::Hostname; my $host = hostname; my $group = 'sbo'; my $newstring = 'sbo::18659:x0929,x1465,x1368,x5552'; my $backup = "/tmp/groups"; copy ("$backup", "$backup.tmp") or die "can not copy $backup"; tie my @lines, 'Tie::File', "$backup" or die "can not open $backup $!" +; for (@lines) { if (/$group/) { $_ .= $newstring; last; } } untie @lines; print "\n $host \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I escape a :: in s///?
by ikegami (Patriarch) on Aug 14, 2009 at 19:56 UTC |