Re: Tie::FILE vs open
org chen wrote: I have a huge file, there are 47,286,116 lines. I am search a line and repalce this line with another string. I know this line is between 20,000,000th to 30,000,000th lines. Which way is more fast and safe: method 1: use Tie::FILE; tie my @array, 'Tie""File', "aa.txt", memory =>100_000_000 or die; for(my $i = 2000; $i < 3000; $i ++){ ... } untie @array; method 2; open(AA, "aa.txt"); while(){ ... } close(AA); 20,000,000 is about at the middle of the file so start there first: use Fcntl ':seek'; open my $AA, '<', 'aa.txt' or die "Cannot open 'aa.txt' $!"; seek $AA, ( -s $AA ) / 2, SEEK_SET or die "Cannot seek 'aa.txt' $!"; while ( <$AA> ) { ... } close $AA; John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Tie::FILE vs open
Thanks for your reply. Why do you think the second way is better? Is the reason: Tie::File don't use memory much? Is open a file and read is always a better solution than Tie::File? In which case we use Tie::File rather than . Org> Date: Mon, 29 Sep 2008 12:57:50 +0800> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Subject: Re: Tie::FILE vs open> CC: beginners@perl.org> > On Mon, Sep 29, 2008 at 12:34 PM, org chen <[EMAIL PROTECTED]> wrote:> >> > I have a huge file, there are 47,286,116 lines. I am search a line and repalce this line with another string. I know this line is between 20,000,000th to 30,000,000th lines. Which way is more fast and safe:> >> > The second way.> while(<>) will read one line at each time.> > -- > To unsubscribe, e-mail: [EMAIL PROTECTED]> For additional commands, e-mail: [EMAIL PROTECTED]> http://learn.perl.org/> > _ Are you paid what you're worth? Find out: SEEK Salary Centre http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek%2Ecom%2Eau%2Fcareer%2Dresources%2Fsalary%2Dcentre%2F%3Ftracking%3Dsk%3Ahet%3Asc%3Anine%3A0%3Ahot%3Atext&_t=764565661&_r=OCT07_endtext_salary&_m=EXT
from perl review (first article) question on regex
I was reading perl magazine and saw sub readable { my $number = shift; $matched = $number =~ s{ (\d+) (\d{3}) (,|$) }{$1,$2$3}x; } while ($matched); return $number; } on test driven development article by Denis Kosykh. I am not sure what (,|$) is doing... Can someone please explain? thank you. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Tie::FILE vs open
On Mon, Sep 29, 2008 at 12:34 PM, org chen <[EMAIL PROTECTED]> wrote: > > I have a huge file, there are 47,286,116 lines. I am search a line and > repalce this line with another string. I know this line is between > 20,000,000th to 30,000,000th lines. Which way is more fast and safe: > The second way. while(<>) will read one line at each time. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Tie::FILE vs open
I have a huge file, there are 47,286,116 lines. I am search a line and repalce this line with another string. I know this line is between 20,000,000th to 30,000,000th lines. Which way is more fast and safe: method 1: use Tie::FILE; tie my @array, 'Tie""File', "aa.txt", memory =>100_000_000 or die; for(my $i = 2000; $i < 3000; $i ++){ ... } untie @array; method 2; open(AA, "aa.txt"); while(){ ... } close(AA); Thanks Org. _ It's simple! Sell your car for just $40 at CarPoint.com.au http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fsecure%2Dau%2Eimrworldwide%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641&_t=762955845&_r=tig_OCT07&_m=EXT
Re: negate a string
On Sun, 2008-09-28 at 12:18 -0700, loke wrote: > Hi. I am trying to filter strings which do not have :// in them, I am > able to find strings with :// but I want to do the exact opposite. > > regex to match : /(.*:\/\/.*)/i > > I tried /(.*(?!:\/\/).*)/i but it does not work. > > Loke > > What code do you have? if( $string =~ m{://} ){ # has :// }else{ # doesn't have :// } -- Just my 0.0002 million dollars worth, Shawn Linux is obsolete. -- Andrew Tanenbaum -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
negate a string
Hi. I am trying to filter strings which do not have :// in them, I am able to find strings with :// but I want to do the exact opposite. regex to match : /(.*:\/\/.*)/i I tried /(.*(?!:\/\/).*)/i but it does not work. Loke -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: dynamically input fields to select from my table in the database
Goke Aruna wrote: > Can someone be of help; > > I have the code below, what i wanted this code to do is to dynamically > create fields to select and again to dynamically subtitute the value of the > given fields. > > my sms content is the source of my data and my table definition is as below: > > (Id int auto_increment primary key, > Name varchar(32), > TradeName varchar(20), > Address varchar(50), > City varchar(13) > State varchar(10), > phone varchar(30), > IndType varchar(20) > ); > > user can determine their known and unknown fields as they like.. I should be > able to know which fields to select and which fields is supplied by the > user. > > Thanks > > goksie > > > #!/usr/bin/perl > # > use warnings; > use strict; > use DBI; > > my ($dsource, $user, $pass, $ret, $sql, $dbh, $sth, $row, $port, $hostname, > $database, $data); > $user='test'; ## user sade need select only access to the table > yellopgdb.yellopg > $pass='test123'; > $port='3306'; > my $name='localhost'; > $dsource="dbi:mysql:yellopgdb:$name"; > $dbh = DBI->connect( $dsource, $user, $pass )|| die ("Couldn't connect to > yellopgdb !\n"); > > > #user supplies name unknown, address unknown, > # > #user send sms to myphonenumber with content tradename,onet city,ibadan > #name,query phone,query indtype,query > # > > my $smscontent = > "tradename,onet,city,ibadan,name,query,phone,query,indtype,query"; > my %sms =split(/,/, $smscontent); > my @smswanted =(); > my @given =(); > # > foreach(keys %sms){ > push @smswanted, $_ if $sms{$_} eq 'query'; > push @given, $_, $sms{$_} if $sms{$_} ne 'query'; > } > > =begin > $cname = $coy{'name'}; > $ctradename = $coy{'tradename'}; > $caddress = $coy{'address'}; > $ccity = $coy{'city'}; > $cstate = $coy{'state'}; > $cphone = $coy{'phone'}; > $cindtype = $coy{'indtype'}; > =end > =cut > > my $qry = "select $smswanted[0],$smswanted[1],$smswanted[2] from yellopg > where $given[0]=? and $given[2]= ?"; > $sth = $dbh->prepare($qry); > $sth->execute($given[1], $given[3]); > my @userinfo = $sth->fetchrow_array; > print @userinfo; What is your question? The code you have written looks like it should work. Are you having problems with it? Where do you want to go from here? Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
dynamically input fields to select from my table in the database
Can someone be of help; I have the code below, what i wanted this code to do is to dynamically create fields to select and again to dynamically subtitute the value of the given fields. my sms content is the source of my data and my table definition is as below: (Id int auto_increment primary key, Name varchar(32), TradeName varchar(20), Address varchar(50), City varchar(13) State varchar(10), phone varchar(30), IndType varchar(20) ); user can determine their known and unknown fields as they like.. I should be able to know which fields to select and which fields is supplied by the user. Thanks goksie #!/usr/bin/perl # use warnings; use strict; use DBI; my ($dsource, $user, $pass, $ret, $sql, $dbh, $sth, $row, $port, $hostname, $database, $data); $user='test'; ## user sade need select only access to the table yellopgdb.yellopg $pass='test123'; $port='3306'; my $name='localhost'; $dsource="dbi:mysql:yellopgdb:$name"; $dbh = DBI->connect( $dsource, $user, $pass )|| die ("Couldn't connect to yellopgdb !\n"); #user supplies name unknown, address unknown, # #user send sms to myphonenumber with content tradename,onet city,ibadan #name,query phone,query indtype,query # my $smscontent = "tradename,onet,city,ibadan,name,query,phone,query,indtype,query"; my %sms =split(/,/, $smscontent); my @smswanted =(); my @given =(); # foreach(keys %sms){ push @smswanted, $_ if $sms{$_} eq 'query'; push @given, $_, $sms{$_} if $sms{$_} ne 'query'; } =begin $cname = $coy{'name'}; $ctradename = $coy{'tradename'}; $caddress = $coy{'address'}; $ccity = $coy{'city'}; $cstate = $coy{'state'}; $cphone = $coy{'phone'}; $cindtype = $coy{'indtype'}; =end =cut my $qry = "select $smswanted[0],$smswanted[1],$smswanted[2] from yellopg where $given[0]=? and $given[2]= ?"; $sth = $dbh->prepare($qry); $sth->execute($given[1], $given[3]); my @userinfo = $sth->fetchrow_array; print @userinfo;
Re: Internet explorer viewing options, run script but was prompted to download
Seems you didn't have the webserver configured correctly to run cgi scripts for the req-path of cgi-bin. On Sun, Sep 28, 2008 at 2:28 PM, itshardtogetone <[EMAIL PROTECTED]> wrote: > Hi, > I use internet explorer 7.0 to browse the website. > I upload a simple script, helloworld.cgi, to my website but when I ran the > script by typing the url, www.myurl.com/cgi-bin/helloworld.cgi, instead of > executing the script, I was prompted to download the script. > What must I do. > Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/