Hey guys, "new" to perl and working on first script to parse some verbose output to csv lines. Thought I had it working until I realized that there was a couple of lines in the input that were formatted different. Long story short, In the input file "$path" is usually the first instance of "/ifs/*", but I found that in some cases if the path name was considered to long by the OS command... it truncated the line with "..." and reported the full pathname in one line below the normal field location i.e.:

Type Path Policy Snap +Usage -------------------- ------------------------------ ----------- ----- +-------- directory /ifs/home/admin enforcement no + 32K [hard-threshold] ( 1.0G) [hard-threshold-exceeded] (no) [container] [usage-with-no-overhead] ( 32K) [usage-with-overhead] ( 103K) [usage-inode-count] (4) directory /ifs/home/ftp enforcement no + 31B [hard-threshold] ( 1.0G) [hard-threshold-exceeded] (no) [container] [usage-with-no-overhead] ( 31B) [usage-with-overhead] ( 6.0K) [usage-inode-count] (3) directory /ifs/gpd/data/trufusion/dat... enforcement no + 43G /ifs/gpd/data/trufusion/data0003 [hard-threshold] ( 80G) [hard-threshold-exceeded] (no) [container] [usage-with-no-overhead] ( 43G) [usage-with-overhead] ( 95G) [usage-inode-count] (606)

Figured I have to use a if/else statement checking for the presence of "..." and perform one or two actions (based of input formatting to grab the full "path" word. Here is what I have so far. I commented out the else line temp until I can figure out why the "if" is always false regardless of what I try:

#!/usr/bin/perl -w my $filename = "quotas.txt"; open FILE, "$filename" or die "Cannot open $filename for reading: $!\n +"; open REPORT, ">report.csv" or die "Cannot open report.csv for writing: + $!\n"; undef $/; my $file = <FILE>; $/ = "\n"; my ($header,@records) = split /directory\s+/, $file; while (@records){ my $line = shift @records; if ($line !~ /\.\.\./) { my ($path, $usage, $threshold) = $line =~ / (\S+) #grab path \D+ (\d\S+) #stop at the first digit for usage .*? \[hard-threshold\] #seek out threshold .*? \(\s+(.*?)\) #capture threshold inside parens /sx; print REPORT "$path,$usage,$threshold\n"; } print $line # else { # my ($usage, $path, $threshold) = $line =~ / \S+ #grab path # \D+ # (\d\S+) #stop at the first digit for usage # .*? # (\S+) # \[hard-threshold\] #seek out threshold # .*? # \(\s+(.*?)\) #capture threshold inside parens # /sx; # print "$path,$usage,$threshold\n"; # } }

Can someone please put me on the right path on how to check if "$line" contains text pattern "..." for my if statement??? Thanks!!!


In reply to Checking is variable contains literal periods in if statment... by CTinMich

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.