Re: regular expression problem ? and * characters



In article <1148814104.790698.106250@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"compboy" <compboyxyz@xxxxxxxxx> wrote:

Im writing a perl script now and this is part of the sricpt

chomp = ($pattern = ARGV[0]);

for each(@thisarray)
{
if($_ =~ m/$pattern/i)
{
print ("found it here, $_");
}
}

the array @thisarray is given.

this scprit reads from the command line and pass that input the the
pattern
and will check if the pattern match the any string inside the array it
will
print the msg.

I have done this part succesfully if the input is just a normal string
like a ab

my question is how do you imporve it so it can accept the input that
contains* and ?
character(s) like *ab? a*b* *a*

thanks a lot.

I think you only have to put the '*ab', etc. in single quotes on the
command line.

This example works if you do that: (I called it reg.pl)

#!/usr/bin/perl

use strict;
use warnings;
use Carp;
$|++;

my $regex = shift;

my @array = qw(this that there fore);

for(@array) {
print $_, "\n" if /$regex/;
}
__END__

When I run it with
reg.pl 'th*'
I got:
this
that
there

Boyd
Jer 29.11
.



Relevant Pages

  • SUMMARY: Help! Self Induced 6540 Catastrophe
    ... firmware command for a StorageTek 6540 to revert a 'reset array' ... rather than manually recreating the LUNs. ... I've finally caught up after losing everything on this array. ...
    (SunManagers)
  • Re: Referencing Korn Shell Array Names as a Variable
    ... Your idea worked for displaying the output from the command. ... $ echo $ ... # Attempt to use variable array name and index to reference array value ... The issue is with this line of the script ...
    (comp.unix.shell)
  • Re: command line arguments and processing of the arguments
    ... Another possibility for writing the parser would be to have an array of the ... Then you'll have your actual dispatch table. ... I would guess that in your program the motor to which the command affects ... might be another parameter for the handler function, ...
    (comp.programming)
  • array element count (was: Re: problem with whitespace not splitting on split. -SOLVED - with
    ... #$arrayname that has the count of array elements. ... @ARGV The array @ARGV contains the command-line arguments intended ... See $0 for the command name. ... assignment to $[can be seen from outer lexical scopes ...
    (perl.beginners)
  • Re: Editable input from the console windows
    ... I learning the syntax and build upon a previously working script. ... My case, read, and history statements are mucked up. ... # The code block that the populate the array with id3tag data has been remove. ... You are passing the entire contents of $VAR as a command name (by ...
    (comp.unix.shell)