in reply to Parsing Issue while using Variable name in Pattern
Hm, I cannot reproduce the issue:
#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; push @::Lines, $_; } for my $machine (qw(machine1 machine11 machine12 machine2 machine20 machine23 machine30)) { for my $line (sort @::Lines) { if ($line =~ m/\Q$machine\E\b/){ print "$machine : $line\n"; } } } __DATA__ \\hostname\Cpu(123:machine1)\%Ready \\hostname\Cpu(3545:machine11)\%Used \\hostname\Memory(3244:machine30 (ef0a-14f09a-dfe230d-ea5f8d))\Swapped + MBytes
Output (as expected):
machine1 : \\hostname\Cpu(123:machine1)\%Ready machine11 : \\hostname\Cpu(3545:machine11)\%Used machine30 : \\hostname\Memory(3244:machine30 (ef0a-14f09a-dfe230d-ea5f +8d))\Swapped MBytes
Update: sorry, misread your post... (quotes with "machine30 (ef0a-14f09a-dfe230d-ea5f8d)" would've made it clearer — which only goes to show that a piece of runnable code is often better than prose).
|
|---|