Note that there are some explanatory texts on larger screens.

plurals
  1. POperl - help passing/looping in arguments from file or within a separate perl data structure
    primarykey
    data
    text
    <p>I have a while loop that reads in a single file:</p> <pre><code>my %MyItems = (); while (my $line = &lt;&gt;) { chomp $line; if ($line =~ m/(.* $mon $day) \d{2}:\d{2}:\d{2} $year: ([^:]+):backup:/) { my $BckupDate="$1 $year"; my $BckupSet =$2; $MyItems{$BckupSet}-&gt;{'MyLogdate'} = $BckupDate; $MyItems{$BckupSet}-&gt;{'MyDataset'} = $BckupSet; if ($line =~ m/(ERROR|backup-size|backup-time|backup-status)[:=](.+)/) { my $BckupKey=$1; my $BckupVal=$2; $MyItems{$BckupSet}-&gt;{$BckupKey} = $BckupVal; } } } </code></pre> <p>The script is executed like so, passing in the log file as an argument:</p> <pre><code>./hashtst3.pl /var/log/server1.log </code></pre> <p>My next progression of this script is to:</p> <pre><code>1-read more than 1 log file 2-store the hostname of where the logfile is from 3-eventually print this data out with the other hashes </code></pre> <p>Would I store this information in a separate text file to read in? Would I use a hash for this? </p> <pre><code>server1 /var/log/server1.log server2 /var/log/server2.log server3 /var/log/server3.log ... </code></pre> <p>here are my print statements:</p> <pre><code>#Final print format print "### Verify Final Output\n"; for my $PrintItems (sort keys %MyItems) { my %PrintVal = %{$MyItems{$PrintItems}}; for my $PrintKey (sort keys %PrintVal) { printf "%s=&gt;%s;\n", $PrintKey, $PrintVal{$PrintKey}; } print "\n"; } </code></pre> <p>Here is my output as of adding code referencing {$server}:</p> <pre><code>### Verify Final Output abc2.cfl.mil.mad=&gt;HASH(0x9da338c); abc3.mil.mad=&gt;HASH(0x9e20708); abc4.mad_lvm=&gt;HASH(0x9e20660); abc1.mil.mad=&gt;HASH(0x9e20774); backup-size=&gt;187.24 GB; backup-status=&gt;Backup succeeded; backup-time=&gt;01:54:27; backup-size=&gt;46.07 GB; backup-status=&gt;Backup succeeded; backup-time=&gt;00:41:06; backup-size=&gt;422.99 GB; backup-status=&gt;Backup succeeded; backup-time=&gt;04:48:50; </code></pre> <p>Adding current output per help, using dumper:</p> <pre><code>$VAR1 = 'server1'; $VAR2 = { 'abc1.mil.mad' =&gt; { 'ERROR' =&gt; ' Error mesg here', 'MyLogdate' =&gt; 'Fri Aug 06 2010', 'MyDataset' =&gt; 'abc1.mil.mad' }, 'abc2.cfl.mil.mad' =&gt; { 'backup-size' =&gt; '187.24 GB', 'MyLogdate' =&gt; 'Fri Aug 06 2010', 'backup-status' =&gt; 'Backup succeeded', 'backup-time' =&gt; '01:54:27', 'MyDataset' =&gt; 'abc2.cfl.mil.mad' }, 'abc3.mil.mad' =&gt; { 'backup-size' =&gt; '46.07 GB', 'MyLogdate' =&gt; 'Fri Aug 06 2010', 'backup-status' =&gt; 'Backup succeeded', 'backup-time' =&gt; '00:41:06', 'MyDataset' =&gt; 'abc3.mil.mad' }, 'abc4.mad_lvm' =&gt; { 'backup-size' =&gt; '422.99 GB', 'MyLogdate' =&gt; 'Fri Aug 06 2010', 'backup-status' =&gt; 'Backup succeeded', 'backup-time' =&gt; '04:48:50', 'MyDataset' =&gt; 'abc4.mad_lvm' } </code></pre> <p>Sample output I am looking to print:</p> <pre><code>MyHost=&gt;Server1;MyDataset=&gt;abc2.cfl.mil.mad;MyLogdate=&gt;Fri Aug 06 2010;backup-size=&gt;187.24 GB;backup-status=&gt;Backup succeeded;backup-time=&gt;01:54:27; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload