Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: While Loops

by CountZero (Bishop)
on Jan 08, 2013 at 19:54 UTC ( [id://1012326]=note: print w/replies, xml ) Need Help??


in reply to While Loops

Wait. Stop. Take one step back and ask yourself "Why do I need to print the records 100 at a time"?

In the end there is no difference between printing the records as soon as they are read in, or waiting till the end and then printing them all at once, or anything else in between these two extremes. The end is that you have a screen (or several screens) full of data.

Output is usually buffered anyhow, so printing in "blocks" of 100 is unlikely to speed things up or make your program more performant.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^2: While Loops
by Anonymous Monk on Jan 08, 2013 at 20:29 UTC

    I'm not really trying to print, I was just using that as an example. I apologize for not being specific enough. My code is below and I'm basically opening a file and storing it into an array. I then take the first column and query our Quickbase database to return the primary key, then I map that primary key to @data and import back into Quickbase.

    The problem is I can only do the gen_results_table call for a 100 stores at a time, so I have to run that gen_results_table statement once for every 100 stores.

    #!/usr/bin/perl require 'c:/quickbase.pm';#REF Perl SDK use LWP; my $url = "http://somesite.com/forcast.txt"; my $ua = LWP::UserAgent->new(); $ua->proxy(['http'],'http://ourproxy.oursite.com:80'); $ua->credentials($netloc, $realm, $uname, $pass); my $response = $ua->get($url); open (FILE, ">C:\\snow.txt") || die "Can't open Snow.txt $!\n"; print FILE $response->content; close(FILE); open (FILE, "<C:\\snow.txt") || die "Can't open Snow.txt $!\n"; my $column=0; while ($line = <FILE>){ chomp($line); push @data, [split /\t/,$line]; } close(FILE); @column = map {$$_[0]} @data; shift(@column); $stores = join( ' OR ',@column); my $qdb = HTTP::QuickBase->new(); $qdb->proxy('http://ourproxy.oursite.com:80'); $qdb->url_prefix("https://www.quickbase.com/db"); $qdb->authenticate("MyUserName","MyPass"); $qdb->apptoken('bj6azdybdeg8akbcu5ggabfdedsi'); my $recid=$qdb->gen_results_table("babvce7n4",{query=>"{'6'.EX.$stores +}",clist=>"3",options=>"csv"}); my @recids = split /\n|\r\n/,$recid; my $i = 0; @data = map{unshift(@{$_},$recids[$i++]);$_} @data; $a = join( "\n", map {join(',',@{$_})} @data); my $import = $qdb->import_from_csv("bhabcde7f",$a,"6.7.8.9.10.11.12.13 +.14.15.16.17.18.19.20.21.22.23.24.25","1");

    Keep in mind I am new to Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1012326]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-24 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found