Hello Monks, this question is probably rudimentary but I can not seem to figure it out on my own. I have a file and in it is a bunch of paths like this: "\\my.domain.net\Apps\Sketchup" "\\fs-10\licenses\Sketchups" and so fourth - there are alot of lines in this file. I am trying to write a script that takes standard in like ./script.pl "Apps\Sketchup" and then matches the line in the file and sets the first column to one variable and the second colums to another variable sans the quotes. But I am stuck on the matching at this point. Here is my script so far:
$my_default="\\\\my\.domain\.net\\"; $my_file="info.txt"; my $path = shift @ARGV; sub usage{ print STDERR "\nUsage:\n"; print STDERR "\t$0 \"the\path\"\n"; print "\n"; } sub grep_pattern{ # print "$patten\n"; foreach (@my_data) {print "$_\n" if /$pattern/; } print "\n\n"; } sub print_array{ for ($i=0; $i<=$#my_data;$i++) {print $my_data[$i], "\n"; } print "\n\n"; } unless ($path){ &usage; exit (-1); } open(HANDLE, $my_file) || die("Open the file failed!"); @my_data=<HANDLE>; print_array; # Try and find the ARGV $pattern = $path; print "Searching for: $pattern\n"; grep_pattern;
At this point I cant even get a match. Can one of you Monks point me in the right direction. Thanks in advance

In reply to Pattern matching and setting the match to a variable by mrbbq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.