Perl "unlink" function usge with "glob" -


i want delete files "1.1.1.1" ip address in /tmp folder:

# ls -1 /tmp 1.1.1.1_reboot.xml 1.1.1.1_roll.xml 1.1.1.1_setup.xml 1.1.1.2_reboot.xml 1.1.1.2_roll.xml 1.1.1.2_setup.xml 

i referring: unlink , glob

here code:

#!/usr/bin/perl -w use strict;  $dir     = "/tmp"; $ip      = '1.1.1.1';  unlink glob $dir."/".$ip."*"; 

however, not deleting files. suspicion on glob function , guess not using in right fashion.

could help. thanks.

update:

if replace $ip ip address itself, deleting files.

unlink glob $dir."/"."1.1.1.1"."*"; 

so, looks unlink statement not able evaluate value of variable $ip. not know why behaving way. need make work $ip , not explicit value.

it may retated path. print error more information. try this:

#!/usr/bin/perl -w use strict;  $dir     = "/tmp"; $ip      = '1.1.1.1';  chdir $dir; @goners  = glob $ip . "*";  foreach $file ( @goners ) {    print "file: $file\n";    next unless $file =~ m!^1\.1\.1\.\d_!;    print "file delete: $file\n";    unlink $file or warn "could not unlink $file: $!"; } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -