Thanks for the info on error using open and $! I have implemented it in.
I got to my computer to test it turns out that I had a variable misspelled which resulted in emptyness oh and I didn't use curl properly (well I didn't really know what curl was but now I do kinda).
Enjoy script.
Let me know if it works
Code:
use strict;
# this code is not tested I'm at school right now using windows machine
# with no perl
# read a line (assuming file is opened using open())
# place your url here
# this q{} may help with programming syntax which
# will help prevent the "bareword" problem that was encountered
my $URL = q{http://example.com};
my $i;
my $file;
my $verb=0; # verbious
for($i = 0; $i < @ARGV; $i++){
if($ARGV[$i] eq "-v"){
$verb = 1;
} else {
$file = $ARGV[$i];
}
if($ARGV[$i] eq "--help"){
print "perl script.pl file [-v]\n-v for verbous\n";
exit(0);
}
}
if(!$file){
print "Please enter a file name\n";
$file = <>;
}
if(!(-e $file)){
print "file doesn't exit\n";
}
open (file, "$file") or die ("couldn't open $file\nError: $!");
my $r;
my $line = 1;
while(<file>){
my $read;
$read = $_;
chomp $read;
# get relevent data
$read =~ /(.*?),(.*?),(.*?),(.*?)/;
my ($num, $date, $reason, $enable);
$num = $1;
$date = $2;
$reason = $3;
$reason =~ s/ /+/g;
$enable = $4;
if(!$read){ next; }
if($enable eq "yes"){
# put code to do something here if you want
# I think you mean to have plus signs there too?
$enable = "ETC+Applies";
} else {
$enable = "No+ETC";
}
# its case sensitive so the below and above need to match case
my $cmd;
$cmd = qq{curl "$URL/index.php?number=$num&date=$date&reason=$reason&enabled=$enable"};
print "$cmd\n" if($verb);
$r = system($cmd);
if($r != 0){
print "Error: couldn't run curl on line $line\n$read\n";
}
}
close file;