Home > Archive > PERL Beginners > October 2004 > cat *.txt > .txt...........roy
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
cat *.txt > .txt...........roy
|
|
| Roime bin Puniran 2004-10-25, 3:56 am |
| Hi all..i have wrote a script that import from several text file into =
mysql..
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
#!/usr/local/bin/perl
use CGI ':standard';
use strict;
use warnings;
use DBI;
#my $dbh =3D DBI->connect("dbi:mysql:ayam","root",telekom);
#Prepare the insert SQL
my $rec =3D $Package::dbh->prepare("INSERT INTO t_flows(ipSrc, ipDst, =
pktSent, bytesSent, startTime, endTime, srcPort, dstPort, tcpFlags, =
proto, tos) VALUES ('$value1', '$value2', '$value3', '$value4', =
'$value5', '$value6', '$value7', '$value8', '$value9', '$value10', =
'$value11')");
$rec->execute;
my $path =3D "/home/roime/flow/";
my @folder =3D <$path>;
my $file =3D ".flow";
foreach my $file (@folder)
{
my $full_path =3D $path.$file;
open(FILE, $full_path)||die("Could not read file !");
$Package::file_contents =3D <FILE>;
close(FILE);
=09
}
my @file_array =3D split($file_contents);
my @counter =3D 0;
for each my @file_array(@counter)
{
my @value1 =3D $file_array[$counter];
$counter =3D $counter + 1;
my @value2 =3D $file_array[$counter];
$counter =3D $counter + 1;
my @value3 =3D $file_array[$counter];
$counter =3D $counter + 1;
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
when i try to run it and try to transfer the data into variable and from =
the , i got this error on my code
"Missing $ on loop variable at texttest.pl line 31."
.....Do you guys have an opinion?..
This e-mail and any attachments may contain confidential and
privileged information. If you are not the intended recipient,
please notify the sender immediately by return e-mail, delete this
e-mail and destroy any copies. Any dissemination or use of this
information by a person other than the intended recipient is
unauthorized and may be illegal.
| |
| Chris Devers 2004-10-25, 3:56 am |
| Why are you sending two copies of your mail to the list?
Please stop doing that -- it's a great way to get ignored.
On Mon, 25 Oct 2004, Roime bin Puniran wrote:
> Hi all..i have wrote a script that import from several text file into mysql..
>
> ========================================
===================================
>
> #!/usr/local/bin/perl
>
> use CGI ':standard';
> use strict;
> use warnings;
> use DBI;
>
> #my $dbh = DBI->connect("dbi:mysql:ayam","root",telekom);
>
> #Prepare the insert SQL
> my $rec = $Package::dbh->prepare("INSERT INTO t_flows(ipSrc, ipDst, pktSent, bytesSent, startTime, endTime, srcPort, dstPort, tcpFlags, proto, tos) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9'
, '$value10', '$value11')");
> $rec->execute;
>
> my $path = "/home/roime/flow/";
> my @folder = <$path>;
> my $file = ".flow";
>
> foreach my $file (@folder)
> {
> my $full_path = $path.$file;
> open(FILE, $full_path)||die("Could not read file !");
> $Package::file_contents = <FILE>;
> close(FILE);
> }
>
> my @file_array = split($file_contents);
> my @counter = 0;
>
> for each my @file_array(@counter)
> {
> my @value1 = $file_array[$counter];
> $counter = $counter + 1;
> my @value2 = $file_array[$counter];
> $counter = $counter + 1;
> my @value3 = $file_array[$counter];
> $counter = $counter + 1;
> }
>
> ========================================
==============
>
> when i try to run it and try to transfer the data into variable and
> from the , i got this error on my code
>
> "Missing $ on loop variable at texttest.pl line 31."
> ....Do you guys have an opinion?..
It looks like this line is the problem:
for each my @file_array(@counter)
That is not the way to write a `foreach` loop. Try something like:
foreach $scalar ( @list ) { ... }
You're doing something.... starkly different.
--
Chris Devers
|
|
|
|
|