Reputation: 9
I have a perl script that works fine when I run it using perl filename, however when I use the command
perl -w logint > logintime.html
I get this error
Use of uninitialized value $days in multiplication (*) at logint line 5, <LAST> line 3.
It repeats this from line 3-47
This is the perl code
#!/usr/bin/perl
open LAST, "last |";
while (<LAST>) {
if (($name,$days,$hours,$mins) = /^(\w+).+\((?:(\d+)\+)?(\d+):(\d+)/) {
$TIMES{$name} += 1440 * $days + 60 * $hours + $mins;
}
}
foreach (sort keys %TIMES) {
print "$_ $TIMES{$_}\n";
}
This is how I'm attempting to output it.
#!/bin/bash
echo $HDR > ~/public_html/logintime.html
perl -w logint > logintime.html
echo $FTR >> ~/public_html/logintime.html
Upvotes: 0
Views: 58
Reputation: 316
This is just a warning, it's not an error. You're seeing it when you run that command because '-w' is the warnings pragma.
You could also put it at the end of your shebang
#!/usr/bin/perl -w
Or 'use warnings;'. Anyway, the warning is just saying it doesn't have a value. It looks like you're reading the last log to see who last logged in, the output can be different depending on what OS you're on. I would confirm it's working as expected and getting the correct values.
It's also best practice to use 'use strict;'.
Upvotes: 1