i trying read file. here files looks like..
abc123 abdef012 fedabc_23 xyz12 12345 now, trying is, getting option command line , according entered wildchar like, *, ?, + appropriate lines above file should printed. stuck here. know. how * works, not sure other wildchars.. please me.
#/perl/bin/perl use getopt::long; open (data, "filname.txt") || die "can't open file:$!"; $fil=''; $res= getoptions ( "f=s" =>\$fil ); $fil=~ s/[\*]//g; #works if '*' @ end /(\w*$fil\w*)/ && !$seen{$1}++ && push @arr, $1 while <data>; how use other wildcards also? how generalize this?
let me straight:
you have file, , want input regular expression, , print out lines match expression? grep?
use strict; use warnings; use autodie; $regex = shift; $file = shift; open $fh, "<", $file; #autodie handle not being able open files... while ( $line = <$fh> ) { print $line if $line =~ /$regex/; } close $fh; or, trying use globbing , not regular expressions?
there's perl module called text::glob match on globs or convert glob regular expression.
i never used it, appears pretty simple:
use strict; use warnings; use autodie; use text::glob qw(match_glob); $glob = shift; $file = shift; open $fh, "<", $file; #autodie handle not being able open files... while ( $line = <$fh> ) { print $line if match_glob( $glob, $line ); } close $fh;
Comments
Post a Comment