beanscake has asked for the wisdom of the Perl Monks concerning the following question:

 my $optional = grep $_ eq 'optional:', @ARGV;

is there a way i can grep words after the optional:

like

perl ./see.pl bla bla optional:01 grep 01

of course i know i can use $ARG[0]; TILL my input like i said optional if true process it.. i need help on this

Replies are listed 'Best First'.
Re: help with Grep
by Athanasius (Cardinal) on Mar 30, 2015 at 02:09 UTC

    Hello beanscake,

    Your question is not very clear, but I suspect grep is not the best tool for this job. Are you looking for something like this?

    12:07 >perl -MData::Dump -wE "my @opts; push @opts, /optional:([^\s]+) +/ for @ARGV; dd \@opts;" x y z optional:01 grep 02 optional:z53 ["01", "z53"] 12:09 >

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      thank you

Re: help with Grep
by trippledubs (Deacon) on Mar 30, 2015 at 02:50 UTC
    #!/usr/bin/env perl use strict; use warnings; use Data::Dump; my @options = map { /optional:(.*)\b/g } @ARGV; dd @options;
    Produces:
    ./t.pl alpha bravo optional:charlie optional:delta optional:echo ("charlie", "delta", "echo")
    Re^4: Capturing regex from map