in reply to Delete "/" in a string
The "tr" operator is slightly more efficient than the s//, and serves the purpose well in this case.my ($ip,$interface) = qw(192.168.1.1 POS1/0/0); (my $filename = "$ip--$interface.txt")=~tr{/}{}d; # $filename now contains '192.168.1.1--POS100.txt"
The "d" option at the end of the operator "d"elete's the un-substituted character ("/") in this case.
Update: Another advantage of this approach is that it is non-destructive: The content of $interface is not changed - this is not the case with the previous 2 posts first post.
"You're only given one little spark of madness. You mustn't lose it." - Robin Williams
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Delete "/" in a string
by Laurent_R (Canon) on Oct 23, 2014 at 06:46 UTC | |
|
Re^2: Delete "/" in a string
by AnomalousMonk (Archbishop) on Oct 23, 2014 at 05:32 UTC |