Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

cat *.txt > .txt...........roy
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Roime bin Puniran
10-22-04 08:55 AM


Re: cat *.txt > .txt...........roy
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

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
10-22-04 08:55 AM


Re: cat *.txt > .txt...........roy
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Cole
10-22-04 01:55 PM


RE: cat *.txt > .txt...........roy
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Roime bin Puniran
10-25-04 08:56 AM


RE: cat *.txt > .txt...........roy
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 mysq
l..
>
>  ========================================
==================================
=
>
> #!/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, bytes
Sent, startTime, endTime, srcPort, dstPort, tcpFlags, proto, tos) VALUES ('$value1',
 '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$valu
e9'
, '$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 t
he , 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Cole
10-25-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:39 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.