For Programmers: Free Programming Magazines  


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-22, 3:55 am

Hi...
I have tried to find if any PERL module can do my task..And i found that =
File::Spac can do what i am to do..It's allow us to concatenate several =
..*txt file and sort it into one text file..But, i don't make any perl =
script on it, because i jst wanna see some examples first, to avoid me =
waste my time if it couldn't realize soon.In linux, for additional, we =
actually know know that cat command line can do concatenate works..

shell> cat *.txt > allweather.txt

How perl script can do the same as linux command line like =
above?...Honestly, i don't know where's to start...Do you guys have any =
tips what should i start to make may own script on it?...


-----Original Message-----
From: Gabor Urban [mailto:gabaux@rubin.hu]
Sent: Tue 10/19/2004 8:32 PM
To: Roime bin Puniran
Cc: beginners@perl.org
Subject: Re: .txt To Mysql.......roy
On Tue, 2004-10-19 at 12:12, Roime bin Puniran wrote:
> Hi..
> I have 30 text file that contains of sort of data about =

wheather...Each text file contains the information about weather in one =
day. So, i have 30 text file, which contains all the info about weather =
in 30 days(1 month). All the attributes in all the text files are same =
(date, date, rain scalar, celcius), but the the data / value in there =
are absolutely different. So, how i can dump all this data into =
mysql?...I have create a table named weather in Mysql, and the =
attributes in this table are same with my text files...
> My question is, how can I dump all the data from text file into mySQL =

without specifies the names of the text file..It's mean that, we only =
specifies the extention of text file (*.txt) then by that way i can dump =
all into mysql?...
> Did i need to develop some PERL script to read an extension (.txt) and =

read them then import them into mysql or mysql itself provide some =
sommand to do so?...

HI,

I guess no, quite sure, that MySQL has an import feature. Try to check
the documention.

Good luck

Gabaux


--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>






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.

--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>






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-22, 3:55 am

On Fri, 22 Oct 2004, Roime bin Puniran wrote:

> I have tried to find if any PERL module can do my task..And i found
> that File::Spec can do what i am to do..


So.... why are you asking the list then?

> shell> cat *.txt > allweather.txt


So... we should just write this for you, just like that?

Come on, you know what you want, and you've found a module that can help
you. Write some code now. Think it through. You want something like:

my @files = get_files_from_input( @ARGV );
my $out = "whatever.txt";

foreach my $file @files {
while <$file> {
append_to_file( $file, $out );
}
}

All you have to do now is write the get_files_from_input() and
append_to_file() subroutines.

Try it. Experiment. When you hit a wall, come back to the list for help.


--
Chris Devers
Chris Cole

2004-10-22, 8:55 am

On Fri, 22 Oct 2004 10:54:24 +0800, Roime bin Puniran wrote:

> Hi...
> I have tried to find if any PERL module can do my task..And i found that
> File::Spac can do what i am to do..It's allow us to concatenate several
> .*txt file and sort it into one text file..But, i don't make any perl
> script on it, because i jst wanna see some examples first, to avoid me
> waste my time if it couldn't realize soon.In linux, for additional, we
> actually know know that cat command line can do concatenate works..
>
> shell> cat *.txt > allweather.txt
>
> How perl script can do the same as linux command line like
> above?...Honestly, i don't know where's to start...Do you guys have any
> tips what should i start to make may own script on it?...
>

Roy, I already answered your question on your previous post yesterday.
Plus I gave you some tips on newsgroup etiquette. All of which you have
ignored. If you continue like this *we* will start to ignore *you*.

Do you really expect someone else to so your work for you? Come on, get a
grip.

Chris.
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 Cole

2004-10-25, 8:55 am

On Mon, 25 Oct 2004 12:43:42 +0800, 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;


Good.

> #my $dbh = DBI->connect("dbi:mysql:ayam","root",telekom);


Why is this commented out? It will cause problems see below.

> #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;


These two lines should fail as you've not connected to the db. Also
$Package::dbh->prepare is unnecessary $dbh->prepare is better.

> my $path = "/home/roime/flow/";
> my @folder = <$path>;
> my $file = ".flow";
>
> foreach my $file (@folder)


This is fine, but you're redeclaring the same variable as above and losing
it's assignment you gave before. Do you want to do this? Again you should
a get a warning from perl about this.

> {
> 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;


Do you mean 'my $counter = 0;'?

>
> for each my @file_array(@counter)


I'm guessing this is line 31. Several probs:
1. @counter is empty.
2. each value in your @counter array is being passed to @file_array and
over-writing it. I think the error you mention below is caused by the
fact you need a scalar variable here (e.g. foreach my $value (@array) {})
3. You mean foreach not 'for each', right?

> {
> my @value1 = $file_array[$counter];
> $counter = $counter + 1;
> my @value2 = $file_array[$counter];
> $counter = $counter + 1;
> my @value3 = $file_array[$counter];
> $counter = $counter + 1;
> }


$counter doesn't exist and the way you're assigning values to arrays is
wrong. For each iteration of the loop you're creating new arrays with only
a single value in each. I'm not sure what you're trying to do, but I think
a while loop would suit better and you must have an ending condition
otherwise it will loop forever.


> ========================================
==============
>
> 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 is much better, Roy. You've actually shown what you've tried rather
than expect us to do it for you.

HTH
Chris.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com