RE: Info from flat file

2008-04-28 Thread Rob Benton
On your question about $/, the answer is yes.  That's why it's always 
recommended you modify that variable inside an anonymous block like this:

{
  local $/ = +===+\n;
  # read your file
}


Look at this page and search for $/.

http://perldoc.perl.org/perlvar.html


Manoj [EMAIL PROTECTED] wrote: I also wanted to fetch the first line after 
the $/ from the beginning. The
line Domain : perl.com should be printed along with the while processing. 

+=+
Domain : perl.com


-Original Message-
From: Manoj [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 25, 2008 1:02 PM
To: 'Chas. Owens'
Cc: 'Perl Beginners'
Subject: RE: Info from flat file

Chas,

I have a question on this. Will the pattern $/ used considered for other
opened files also? I was trying to match the IP with ip-host file and
considering the whole ip-host text file as single line even though there is
newline.

Can you shower some light in this?

Thanks
K

-Original Message-
From: Chas. Owens [mailto:[EMAIL PROTECTED] 
Sent: Sunday, March 16, 2008 4:06 AM
To: Manoj
Cc: Perl Beginners
Subject: Re: Info from flat file

On Fri, Mar 14, 2008 at 3:33 PM, Manoj  wrote:
 I have a log file like this. The part between += are almost similar from
  which I need to fetch for IP Address and Connection time only for domain
  perl.com. The perl.com domain may scattered in log. The main intension of
my
  work is that this log keeps a record of the users who visits websites. I
  have to get the doc printed that contains specific domain visits and
time.
  Thought the below one I will take as a sample data. The IP address can be
  the 10 or 11th line from Domain line. Was first thinking of getting this
by
  using head and tail command in unix. This works for me but for windows
box
  this will be a problem as I don't have cygwin installed which I will not
be
  able to do. All comments are welcomed. Thanks..!
snip

What you need to do is read in the individual records (delimited by
+=+\n) and search for the required fields
with a regex:

#!/usr/bin/perl

use strict;
use warnings;

$/ = +=+\n;

while () {
 chomp;
 next unless length  0;
 next unless my ($ip, $time) = /Domain :
perl\.com.*IP:(\S+).*Connection Time:(\S+)/s;
 print $ip $time\n;
}

__DATA__
+=+

Domain : perl.com

hostname





IP:XXX.XXX.XXX.XXX

Connection Time:XXX secs









+=+

Domain : domain.com

hostname





IP:XXX.XXX.XXX.XXX

Connection Time:XXX secs





+=+

Domain : education.com

hostname

IP:XXX.XXX.XXX.XXX





Connection Time:XXX secs





+=+

Domain : perl.com

hostname

IP:XXX.XXX.XXX.XXX





Connection Time:XXX secs





+=+





-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





special chars as scalar inside regex

2008-03-28 Thread Rob Benton


I've got a problem I think there may be a straight-forward solution to  
that I just don't know.  I have a program that reads a variable-length  
input file. And the field delimiter of that file is given as an  
argument.  The problem is something like pipe | might show up as the  
delimiter.  So is there a way to quote/protect that in the split()  
function without it being interpreted as a regex special character?


Something like:

./myprog.pl |

myprog.pl:
-
my $delimiter = $ARGV[0];
my @fields = split(/$delimiter/, $line);


This is a very simplified example.  Hope that makes sense.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Math::BigInt maximum value

2006-02-08 Thread Rob Benton
What are the limitatins of Math::BigInt?  I ask because I have a c++ 
program that outputs an unsigned 64 bit integer that my perl script 
picks up.  Am I safe to use BigInt for this on all platforms?


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Out of Memory! error on large tied hash

2004-09-27 Thread Rob Benton
Chris Devers wrote:
This may be the sort of problem that would best be handled by a proper 
database server. The folks writing RDBMSes have been tackling problems 
like this for decades now, and have some useful techniques; rather than 
reinvent the wheel, you can just leverage their efforts by putting 
everything into (say) MySQL or PostgreSQL. (Of course, that makes things 
more complicated too, but should at least get you past this problem.)

 

Yes this little job is getting too big for a dbm file.  This was the 
first time I've tried it on anything  8 million.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



using DB_BTREE on an 8mm record file

2004-08-17 Thread Rob Benton
I've been using the DB_File $DB_BTREE module to create groups and sort 
them on an 8 million record file.  Is there a faster way to do this or 
am I still getting pretty good perfomance with this module?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



using tie on a hash of anonymous arrays

2004-08-12 Thread Rob Benton
Is this possible?  I know what I have below won't work.
==
use DB_File;
my %hash;
tie(%hash, DB_File, undef, O_RDWR|O_CREAT, 0640, $DB_BTREE) or die
$hash{1} = [ 2, 3, 4 ];
print @{$hash{1}}\n;
untie(%newhash);
==
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: How to Sort on a substr

2004-07-15 Thread Rob Benton
Jeff Westman wrote:
Hi,
I need to do a sort on a couple of column ranges. 

I want to be able to do a primary sort, on say, columns 21-25 and
then a secondary sort on columns 40-49.
Any ideas on how to approach this?
TIA
/j


__
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
Can you get away with concatenating the 2 substrings?  That would cut 
down your sort to pass.  Either way you'll have to define a sort 
function I think.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Using the () list notation with $scalars

2004-07-01 Thread Rob Benton
I'm looking for a little help here.  I'm not understanding exactly 
what's wrong with this code:

===
#!/usr/bin/perl -w
use strict;
open IN, comma.txt or die $!\n;
my %rows;
while (IN)
{
chomp;
my @fields = split( /,/, $_);
$rows{$fields[2]} = [ ($fields[3]..$fields[-1]) ];
print array: ;
print @{$rows{$fields[2]}}\n;
}
close IN;
===
This prints nothing for the array.  If I replace the scalars inside [ () 
] with literal strings or numbers it works.  What the correct way to do 
what I'm attempting.  Am I just quoting wrong?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Problems getting a simple form to work.

2003-04-04 Thread Rob Benton
Give this a shot and see if it errors:

use CGI;
my $query = new CGI;
my %params = $query-Vars;

my $username = $params{'username'};



On Fri, 2003-04-04 at 15:29, Mike Butler wrote:
 Thanks, Andrew. I added CGI::Carp qw(fatalsToBrowser); to the script. That's
 a big help. The error message that I get now is:
 Software error:
 Undefined subroutine main::param called at simpleform.cgi line 6.
 
 Line 6 is my $username = param('username');
 
 Any idea why param is undefined?
 
 Thanks,
 
   - Mike
 
 
 -Original Message-
 From: Hughes, Andrew [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 3:09 PM
 To: [EMAIL PROTECTED]
 Subject: RE: Problems getting a simple form to work.
 
 
 I would also add
 
 use CGI::Carp qw(fatalsToBrowser);
 
 along with
 
 use CGI;
 use strict;
 
 This way your errors will get displayed in your browser.
 
 Also, check with your hosting company to make sure that your path to perl is
 correct (ex. is it #!/usr/local/bin/perl -wT vs. #!/usr/bin/perl -wT)
 
 Andrew
 
 -Original Message-
 From: Li Ngok Lam [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 04, 2003 2:37 PM
 To: Mike Butler; [EMAIL PROTECTED]
 Subject: Re: Problems getting a simple form to work.
 
 
 [..]
  #!/usr/local/bin/perl -wT
  use CGI;
  use strict;
 
  $username = param('username');
 
 should be :
 my $username = param('username');
 
 because you've using strict;
 
 
  print Content-type: text/plain\n\n;
 For what I know, I would write as Content-type: text/html\n\n;
 
  print You entered: $username\n;
 
  The permissions look like this:
 
  Permissions for cgi-bin: rwxr-xr-x
  Permissions for simpleform.cgi rwxr-xr-x
  Permissions for simpleform.htm: rwxr-xr-x
 
  I have changed form method=post action=../cgi-bin/simpleform.pl to
  form method=post action=http://www.mikyo.com/cgi-bin/simpleform.cgi;.
 
 
 2 suggestion here :
 
 1. use CGI::Carp 'fatalsToBrowser'; # the die message will goto your
 browser.
 2. Try simpler script, so you will know if your form is going to a right
 place :
 
 #!/usr/bin/perl
 print Content-type: text/html\n\n;
 print Hello world;
 
 
 
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem with regular expressions!!!

2003-03-19 Thread Rob Benton
How does it translate?

* = 0 or more of preceding char
? = 1 or 0 of preceding char
*? = ???


On Tue, 2003-03-18 at 21:41, Michael Kelly wrote:
 On Tue, Mar 18, 2003 at 05:53:45PM -0600, Rob Benton wrote:
  It looks odd to me b/c * and ? are both quantifiers...
 
 * and ? alone are both quantifiers, but *? is a non-greedy *.
 
 -- 
 Michael
 [EMAIL PROTECTED]
 http://www.jedimike.net/
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Problem with regular expressions!!!

2003-03-18 Thread Rob Benton
It looks odd to me b/c * and ? are both quantifiers which usually
triggers an error when you try to run it.  See if this works for you:

$file_completename =~ /([^.]*)\.(.*)/;


On Tue, 2003-03-18 at 15:28, Marcelo Taube wrote:
 As u probably have guessed some part of my code is not working properly and 
 i don't understand why!!
 
 This is the code.
 #
 $file_completename =~ /(.*?)\.(.*)/;
 if ($2 eq $extension]) {
   #DO SOMETHING!!!
 }
 #
 As u see, i'm trying to separate the complete name of a file in two parts, 
 the filename ($1) and the extension($2)... then i check to see whatever a 
 extension is of some kind and if it is, i do something.
 However this doesn't work. Because in $2, perl adds a . before the 
 extension.
 4 example: if file_completename equal to myfile.jpeg, then $2 equials to 
 .jpeg, but it should be jpeg.
 What am i doing wrong?
 Thank u very much,
 Marcelo Taube
 
 
 
 _
 The new MSN 8: advanced junk mail protection and 2 months FREE* 
 http://join.msn.com/?page=features/junkmail
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



passing cgi params

2003-03-15 Thread Rob Benton
If I use:

my $query = new CGI;
my %params = $query-Vars;

to grab the incoming parameters is it safe to just send all of them over
to a new cgi script like this:

my $form = CGI::FormBuilder-new( fields = \%params, method = 'POST');
print $form-render();

Or will that pass along built-in parameters that should be?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



CGI::FormBuilder

2003-03-14 Thread Rob Benton
Is there a way to print a 'button' input type without a label next to it
using the FormBuilder object?  I can't find the right combination.

I always wind up with this

 +---+
Next |Next   |
 +---+

and what I want is

 +---+
 |Next   |
 +---+

$form-field(name = 'next', value = 'Next', label = 0)
is all I could think of to try but that doesn't work.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



html table limit

2003-03-12 Thread Rob Benton
Is there a limit to how many rows you can put in an html table?  I can't
find anything wrong with my script but when I get over 1000 rows or so
in my tables they start drawing weird borders.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: html table limit

2003-03-12 Thread Rob Benton
Mozilla, Konqueror, Opera, and IE all act the same way.  Check out this
page to see what I mean.  The top, bottom, and right side of the table
borders act funky:

http://www.geocities.com/emperorrob/test.html

I tried the validator but it keeps timing out. :)  I guess the file is
too big.

On Wed, 2003-03-12 at 12:02, Bob Showalter wrote:
 Rob Benton wrote:
  Is there a limit to how many rows you can put in an html table?  I
  can't find anything wrong with my script but when I get over 1000
  rows or so in my tables they start drawing weird borders.
 
 That would be a function of the browser, so see if your browser has any
 limits. Try viewing the page with different browsers. Also, make sure your
 all your tags are balanced (tr with /tr, td with /td, etc.)
 
 You can run your HTML through a validator such as http://validator.w3.org/
 
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: html table limit

2003-03-12 Thread Rob Benton
1000+ rows is a rare situation on my page but in can happen.  It's a dbi
script.  I couldn't really think of a better design but I am open to
suggestions...

On Wed, 2003-03-12 at 15:07, Brett W. McCoy wrote:
 On 12 Mar 2003, Rob Benton wrote:
 
Is there a limit to how many rows you can put in an html table?  I
can't find anything wrong with my script but when I get over 1000
rows or so in my tables they start drawing weird borders.
 
 I think if you are needing tables on an HTML page that have over a 1000
 rows you might want to redesign your UI.  Just IMHO, of course. :-D
 
 -- Brett
   http://www.chapelperilous.net/
 
 I have never understood the female capacity to avoid a direct answer to
 any question.
   -- Spock, This Side of Paradise, stardate 3417.3
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: html table limit

2003-03-12 Thread Rob Benton
Scroll up and down to the bottom of the page then see if the borders
screw up.

On Wed, 2003-03-12 at 14:57, Bob Showalter wrote:
 Rob Benton wrote:
  Mozilla, Konqueror, Opera, and IE all act the same way. Check out this
  page to see what I mean.  The top, bottom, and right side of the
  table borders act funky: 
  
  http://www.geocities.com/emperorrob/test.html
 
 Hmm, this page displays fine for me in IE6.
 
  
  I tried the validator but it keeps timing out. :)  I guess the file
  is too big. 
 
 I was able to run the validator. The only problem is you're missing a
 head/head section and some complaints about the junk yahoo adds on. No
 problem with the table.
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



CGI::FormBuilder parsing

2003-03-10 Thread Rob Benton
I've noticed that when using the formbuilder that field names that have
underscores in them are replaced with spaces.  And also that if a field
has a '.' in it, that . and everything after are truncated when
printing.  Is there any way to modify this?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]