Hi all,
i hope you can help, I'm having some trouble getting all the data from a file, well just the date and time entries. I'll be doing operations on the data so would like to store it within variables.
My script's output is looking a bit strange...
The file is sent from a server so changing it will be difficult. Nearly all of the data are in quotes except the date and time.
First line of the file are the headings, then the data:
"Car ID" "Descriptio n" "Status" "Condition" "Time arrived" "Location" "car_counrt y"
"ABC123" "Lamborghin i Countach" "used" "good" 17/02/2006 15:00:00 "alpha" "Italy"
My script:
[code=perl]
#!/usr/bin/perl -w
use strict;
print "enter filename\n";
chomp(my $filename = <>);
open(FILE, $filename) || die "can't open $!\n";
while (<FILE>){
if (m/ABC/){
my ($ID, $description, $status, $condition, $time_arr, $location, $country) = split/(\"\w+\")/;
print "ID:$ID\ndescri ption: $description\ns tatus: $status\ncondit ion: $condition\narr vied: $time_arr\nloca tion: $location\ncoun try: $country\n\n";
}
}
[/code]
and the output:
ID:
description: "ABC123"
status: "Lamborghin i Countach"
condition: "used"
arrvied:
location: "good"
country: 17/02/2006 15:00:00
How would i get the date and time? Any assistance would be greatly apprieciated.
i know the issue lies on the 11th line, but this has annoyed me for a bit now :(
thanks for yuor time
g0uki
i hope you can help, I'm having some trouble getting all the data from a file, well just the date and time entries. I'll be doing operations on the data so would like to store it within variables.
My script's output is looking a bit strange...
The file is sent from a server so changing it will be difficult. Nearly all of the data are in quotes except the date and time.
First line of the file are the headings, then the data:
"Car ID" "Descriptio n" "Status" "Condition" "Time arrived" "Location" "car_counrt y"
"ABC123" "Lamborghin i Countach" "used" "good" 17/02/2006 15:00:00 "alpha" "Italy"
My script:
[code=perl]
#!/usr/bin/perl -w
use strict;
print "enter filename\n";
chomp(my $filename = <>);
open(FILE, $filename) || die "can't open $!\n";
while (<FILE>){
if (m/ABC/){
my ($ID, $description, $status, $condition, $time_arr, $location, $country) = split/(\"\w+\")/;
print "ID:$ID\ndescri ption: $description\ns tatus: $status\ncondit ion: $condition\narr vied: $time_arr\nloca tion: $location\ncoun try: $country\n\n";
}
}
[/code]
and the output:
ID:
description: "ABC123"
status: "Lamborghin i Countach"
condition: "used"
arrvied:
location: "good"
country: 17/02/2006 15:00:00
How would i get the date and time? Any assistance would be greatly apprieciated.
i know the issue lies on the 11th line, but this has annoyed me for a bit now :(
thanks for yuor time
g0uki
Comment