stacked processing

2012-04-09 Thread Bryan Harris
Hello there! I love perl's ability to stack processing without intermediate variables, e.g. to read in a pipe, strip off commented lines, pull out column 5, and join, I can just do this: $txt = join , map { (split)[4] } grep { !/^#/ } ; What I haven't figured out is how to do a substitution

Re: redirect STDERR

2010-11-04 Thread Bryan Harris
Thank you! On Nov 2, 5:06 pm, bryan_r_har...@raytheon.com (Bryan R Harris) wrote: I have these lines in my script: ** for my $handle (*STDIN, *STDERR) {     open($handle, +/dev/null) or die $me:  Can't reopen $handle to /dev/null: $!.  Exiting.\n;

perl and Amazon EC2

2010-09-17 Thread Bryan Harris
Has anyone figured out how to run scripts stored on Amazon's S3 service using their EC2 service? - Bryan -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

unicode weirdness

2010-07-25 Thread Bryan Harris
I have code that reads the clipboard, expecting text copied out of Firefox from mint.com. However when I copy the lines I end up with a bunch of unicode characters mixed in. The n-dash is particularly irritating, and I want to change it to a regular hyphen. When I paste into a BBEdit UTF8

unicode weirdness

2010-07-25 Thread Bryan Harris
I have code that reads the clipboard, expecting text copied out of Firefox from mint.com. However when I copy the lines I end up with a bunch of unicode characters mixed in. The n-dash is particularly irritating, and I want to change it to a regular hyphen. When I paste into a BBEdit UTF8

Re: Use of uninitialized value in print at...

2010-06-07 Thread Bryan Harris
On Sun, Jun 6, 2010 at 08:19, Shawn H Corey shawnhco...@gmail.com wrote: On 10-06-05 03:26 PM, Bryan Harris wrote: [console] $ perl -e 'use warnings; $c=undef; printf(%s, $c-[0]{dog})' Use of uninitialized value in printf at -e line 1. [/console] Anything that can help me here?  I

Re: Use of uninitialized value in print at...

2010-06-06 Thread Bryan Harris
On Thursday 03 Jun 2010 19:53:48 Bryan R Harris wrote: Seems like the first time I run a new script I *always* get an error message something like this: Use of uninitialized value in printf at /Users/harrisb/Library/perl/matc line 414. The problem is usually I'm printing several

Re: script output = color highlight to stdout

2010-05-28 Thread Bryan Harris
Try this I wondered if anyone could steer me to some information about making perl script output appear in color highlight on stdout. Something like what modern grep does on linux, where the searched term appears in some color (red) in the output to tty. Try this code snippet:

Compressed data embedded in script

2009-10-04 Thread Bryan Harris
I have about 60 MB of text data I want to include at the bottom of a script. 60 MB is too big for us, but compressed it would be probably only 3-6 MB which is much better. Is there any way to put gzipped data in the DATA section of a script, and conveniently read it? I'd also prefer that my

Re: Seeing if any element of an array is in the current line

2009-08-15 Thread Bryan Harris
Hello, I'm trying to write a simple Perl script to output certain lines from a logfile that contain any of a few phrases. [clip] my @goodlist = (word1, word2); I had some fun with this one lately. =) perl -e '@gl=qw/word1 word2/; print grep {$t = $_;grep {$t=~/$_/} @gl } ' I call that

Re: Convert Array's into hashes

2009-08-06 Thread Bryan Harris
How can I recall only certain keys and their corresponding values of hashes ex : if D_103 then print D_103 value is 2 ex :if D_101 then print D_101 value is 0 You may be looking for this: print $_ value is $mycoolhash{$_}\n if exists($mycoolhash{$_}); or more classically: if

Re: better readline?

2009-08-05 Thread Bryan Harris
On Mon, Aug 3, 2009 at 18:43, Bryan R Harrisbryan_r_har...@raytheon.com wrote: I'm writing a little script where the user enters some data via keyboard. The script in some cases can guess what the user will want to enter, but I'd like the user to be able to override what the computer

Re: On using $_ in subroutines

2009-07-28 Thread Bryan Harris
For example, my temptation was to do this: ** sub isDate { $_ = shift; if (m!\d{2}/\d{2}/\d{2}!) { return 1; } else { return 0; } } Why is this in a subroutine at all? If you are using it like: [stuff cut out] Understood, this

On using $_ in subroutines

2009-07-26 Thread Bryan Harris
Is it not possible to use $_ in subroutines? For example, my temptation was to do this: ** sub isDate { $_ = shift; if (m!\d{2}/\d{2}/\d{2}!) { return 1; } else { return 0; } } ** ... but by modifying $_ I

More custom sorting

2009-05-29 Thread Bryan Harris
Let's say I have a bunch of lines of data in an array, @a: car72 car55 truck31 bike2 car12 truck16 van97 car64 ... and I want to sort them so that the trucks are first, then the vans, the bikes are third, cars are next, and everything else sorted

Re: More custom sorting

2009-05-29 Thread Bryan Harris
Bryan Harris wrote: Let's say I have a bunch of lines of data in an array, @a: car72 car55 truck31 bike2 car12 truck16 van97 car64 ... and I want to sort them so that the trucks are first, then the vans, the bikes are third, cars are next

Re: Array Initialization

2009-05-12 Thread Bryan Harris
[stuff cut out] It is usually best to declare variables in the smallest scope possible so: while (more work to do) { my @array = split $string; # do work on array } Doesn't that try to re-localize (?) the @array variable every time through the loop? i.e. doesn't it re-run the my()

Re: Variable in for loop is not automatically local?

2009-05-04 Thread Bryan Harris
[lots of stuff cut out] Note that the foreach variable is an alias to the loop list so modifying the variable also modifies the list elements. Out of curiosity, is it possible to manually create aliases like this as well? e.g. to make $x an alias to $y? - B -- To unsubscribe, e-mail:

arrays and chomp function

2007-07-29 Thread Bryan Harris
Hi, I'm not sure I understand why this is happening. Maybe someone can explain it to me. No matter how many times I use the chomp() function on my array, when I print the array it always prints the newlines. But I have another array, which will print without the newlines. In the first block of

Re: arrays and chomp function

2007-07-29 Thread Bryan Harris
On 7/30/07, Rob Dixon [EMAIL PROTECTED] wrote: Bryan Harris wrote: I'm not sure I understand why this is happening. Maybe someone can explain it to me. No matter how many times I use the chomp() function on my array, when I print the array it always prints the newlines. But I have

Printing a reference of an array

2007-07-25 Thread Bryan Harris
Hi, I'm trying to figure out how to print the following array. How do I print this type of thing? Please let me know if I'm posting to the wrong list. #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Getopt::Long; my $name; GetOptions('[EMAIL PROTECTED],}' = \$name); print

Re: perl built in function for mean

2006-09-10 Thread Bryan Harris
Bryan Harris wrote: chen li wrote: I want to calculate the mean of an array. I know how to let the job done by using a loop. But I just wonder if Perl has the short-cut/built-in function for this. my @data=(1,1,1); mean=(1+1+1)/3=1;(Any perl built-in function for this?) my $mean

Re: Summary for mean/average calculation in perl

2006-09-10 Thread Bryan Harris
chen li wrote: --- John W. Krahn [EMAIL PROTECTED] wrote: chen li wrote: 6)$mean = eval(join(+, @data)) / @data; Depending on how you understand Perl and what progress you are I prefer 6). Depending on how you understand Perl, 6 is the worst solution. Could you explaind why

Re: Summary for mean/average calculation in perl

2006-09-10 Thread Bryan Harris
:: ... and cute tricks should only be used in cute programs. : : I'll take that as a compliment -- thanks, John! He said cute programs, not cute programmers. ... that he thought it was a cute trick, not me. Ha ha. - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional

Re: perl built in function for mean

2006-09-09 Thread Bryan Harris
$mean = eval(join(+, @data)) / @data; I love perl golf. =) - B Dear all, I want to calculate the mean of an array. I know how to let the job done by using a loop. But I just wonder if Perl has the short-cut/built-in function for this. Thanks, Li my @data=(1,1,1);

Re: perl built in function for mean

2006-09-09 Thread Bryan Harris
I can't believe I just beat John in perl golf, by 14 strokes! (Anyone who knows me knows I just got lucky on that hole...) - B chen li wrote: Dear all, Hello, I want to calculate the mean of an array. I know how to let the job done by using a loop. But I just wonder if Perl has

called too early?

2006-08-29 Thread Bryan Harris
I'm getting this warning in a simple script I'm writing: ** main::overlap() called too early to check prototype at /Users/bh/Library/perl/popdef line 272. ** The subroutine overlap is at the bottom of the script, but so

Re: Many lists

2006-07-05 Thread Bryan Harris
Is there possible to create a n-number of lists in a cycle? I.e. for (1..$n){ my @R.$_; } or smth like this ... I know that 'my' will work only in this loop. So i am waiting for the answer. Do you mean an array of arrays? my @R; for (1..$n) { push @R, [ 1..$_ ]; } Here, each element

reading a line at a time inefficient?

2006-05-16 Thread Bryan Harris
If I'm reading in many-megabyte files, is it considered to be more efficient to read it into an array, then loop over the array? Or is reading a line at a time okay? e.g. ** while () { # do some process with each line }

Re: array question

2006-05-09 Thread Bryan Harris
Oh, yes, a special case. I have long ago abandoned special cases since they lead to errors. Note that `perldoc -f split` starts with: split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split Note: no strings. Strings do not work well when used as the pattern for

Re: generate list in increments of 10's

2006-05-07 Thread Bryan Harris
for my $number ( 0 .. 100 ) { print $number * 10, \n; } Or if you enjoy perl golf: print map {($_*10).\n} 0..100; - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response

Re: simple profiling?

2006-04-02 Thread Bryan Harris
On Sat, 01 Apr 2006 09:29:47 -0700, Bryan Harris wrote: This looks very interesting... I downloaded it, but I have no idea how to install it, though. I'm a modules-idiot. I tried putting the .pm file in the current directory and putting use TimeTick.pm; at the beginning of my code

Re: simple profiling?

2006-04-01 Thread Bryan Harris
On Fri, 31 Mar 2006 18:50:15 -0700, Bryan Harris wrote: I have a script that takes ~5 seconds to run, but I'd like to get it down to 1 sec. My problem is I don't know which part is the slow part. my $start_time = time; (code chunk 1 here) print chunk 1: , time - $start_time, seconds\n

simple profiling?

2006-03-31 Thread Bryan Harris
I have a script that takes ~5 seconds to run, but I'd like to get it down to 1 sec. My problem is I don't know which part is the slow part. So given something like this: ** #! /usr/bin/perl -w (code chunk 1 here) (code chunk 2 here) (code chunk 3 here)

Re: simple profiling?

2006-03-31 Thread Bryan Harris
I have a script that takes ~5 seconds to run, but I'd like to get it down to 1 sec. My problem is I don't know which part is the slow part. So given something like this: ** #! /usr/bin/perl -w my $start_time = time; (code chunk 1 here) print chunk

Re: simple references question

2006-02-23 Thread Bryan Harris
it? Sure. But the end result is by not letting you take shortcuts or write ambiguous code it will make your turnaround time faster and your troubleshooting easier. -Original Message- From: Bryan Harris [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 22, 2006 6:47 PM To: Beginners

Re: simple references question

2006-02-22 Thread Bryan Harris
Thanks! Regarding your note, out of curiosity, how will it help a lot in the end? I've been scripting for almost 5 years now, and have produced 100 scripts that are used in data analysis work by ~15 people, and have never used use strict, nor declared any variables with my. Everybody says it's

bizarre math

2005-12-03 Thread Bryan Harris
I just ran into this today, and have no clue what's going on: % perl -e 'print 10-5.5, \n' 4.5 % perl -e 'print 10-05.5, \n' 55 How does 10 minus 5.5 equal 55? Obviously it's the leading zero, but I can't think of any reason why it should do that... - B -- To unsubscribe, e-mail: [EMAIL

Re: bizarre math

2005-12-03 Thread Bryan Harris
I just ran into this today, and have no clue what's going on: % perl -e 'print 10-5.5, \n' 4.5 % perl -e 'print 10-05.5, \n' 55 How does 10 minus 5.5 equal 55? Obviously it's the leading zero, but I can't think of any reason why it should do that... It seems that 05 is taken as

backticks in s///?

2005-09-17 Thread Bryan Harris
When I first learned perl I wrote the classic replace text in files script that probably everybody else writes. It is run with: % replace 'sometext' 'some other text' files ... where $match gets the first arg, and $replace gets the second. It didn't work at first, but someone on this list

Re: round up to nearest...

2005-08-22 Thread Bryan Harris
Neat, I like it! Is this the best way to do simple integer round-ups? E.g. 3.2 - 4? I've been using: $nines = 1 - 1/1e10; $value = 3.2; $roundedvalue = int($value + $nines); ... but it looks like $roundedvalue = $value + (-$value % 1) might be better??? - B On Aug 19, Bryan Harris said

round up to nearest...

2005-08-20 Thread Bryan Harris
Not exactly perl, but ... Is there a simple formula to round some value X up to the next multiple of some other value T? I remember seeing another formula for rounding a value X to the nearest multiple of T -- I'd love that one too, if someone has a list of handy formulas. Or is there a

memory usage of an array

2004-10-25 Thread Bryan Harris
The books say that you can add items to an array until you run out of memory... Is there any way for a script to see how much memory is in use so far, versus how much there is left? - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Limits on globbing?

2004-10-25 Thread Bryan Harris
If thats so, here's something to keep you entertained. Yet another script that doesn't work as received... To make it work I had to remove line 1, and then it still threw a bunch of errors at runtime. Still, it's pretty cool. =) - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For

Re: Limits on globbing?

2004-10-23 Thread Bryan Harris
If you have a question and get no response, PLEASE wait more than 90 minutes before sending your question in again. Give it at least a day, if not a couple of days. We're all volunteers here and expectations of immediate responses are not reasonable. Please forgive me! I've gotten more

Limits on globbing?

2004-10-22 Thread Bryan Harris
I have a directory with around 20k files in it (input files to a simulation, if it matters). I've written a perl script that will build a run script for input files, but it doesn't work when I pass a certain limit... (I think it's characters, not number of files.) I'm using the: @files =

Limits on globbing?

2004-10-22 Thread Bryan Harris
I have a directory with around 20k files in it (input files to a simulation, if it matters). I've written a perl script that will build a run script for input files, but it doesn't work when I pass a certain limit... (I think it's characters, not number of files.) I'm using the: @files =

Re: substitute on \Z

2004-10-20 Thread Bryan Harris
Wow. Just when you thought you knew everything about regular expressions, you find out a bunch of stuff you never knew! Thanks Jeff. I hope you're getting credit somewhere for all the help you give on this list, you deserve it. - Bryan On Oct 19, Bryan Harris said: Does anyone happen

substitute on \Z

2004-10-19 Thread Bryan Harris
Does anyone happen to know why this doesn't work as expected? perl -e '$_=1\n;s/\Z/2/g;print' Why does it print 2 twice? Assuming I have to leave the /g modifier in there, how can I prevent this? TIA. - Bryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:

session ids?

2004-09-22 Thread Bryan Harris
I'm still very much a beginner, but I'm starting to see how establishing a concept of sessions could be quite handy for my website. So I was thinking of coming up with session ids, which could be some encoded combination of their ip address, user name, and the date/time of that session's start.

Re: session ids?

2004-09-22 Thread Bryan Harris
Yes, Wiggins and Sean, thank you! That was just the information I needed to point me off in the right direction. Thanks again. - Bryan I'm still very much a beginner, but I'm starting to see how establishing a concept of sessions could be quite handy for my website. So I was

Re: A simple way? A Perl way?

2004-09-01 Thread Bryan Harris
I am looking for a simple Perl way to decode the following, which can be any grouping of number 2-8,9,11,18-21 Into 2,3,4,5,6,7,8,9,11,18,19,20,21 $ perl -le' print join ,, map /(\d+)-(\d+)/ ? $1 .. $2 : $_, split /,/, 2-8,9,11,18-21' 2,3,4,5,6,7,8,9,11,18,19,20,21 Ouch,

Re: A simple way? A Perl way?

2004-08-31 Thread Bryan Harris
From: Jerry Preston mailto:[EMAIL PROTECTED] wrote: : I am looking for a simple Perl way to decode the : following, which can be any grouping of number : :2-8,9,11,18-21 : : Into :2,3,4,5,6,7,8,9,11,18,19,20,21 : : Any Ideas? : : Thanks for Your Time and Help,

Re: Elegant sequencing

2004-08-29 Thread Bryan Harris
I don't claim to be a master, but you can do something along the lines of: $range = '4.3:8.3'; $range =~ /(\d+).(\d+).(\d+).\2/ and print map $_.$2 , $1 .. $3; Since it appears you require that the fractional part be the same for both ends of the range, I'm just capturing the integer

Re: Elegant sequencing

2004-08-29 Thread Bryan Harris
I don't claim to be a master, but you can do something along the lines of: $range = '4.3:8.3'; $range =~ /(\d+).(\d+).(\d+).\2/ and print map $_.$2 , $1 .. $3; Since it appears you require that the fractional part be the same for both ends of the range, I'm just capturing the integer

Re: Elegant sequencing

2004-08-28 Thread Bryan Harris
Nice, Bob, very elegant indeed! I do have a question, I notice you use and like an if..then. What if you wanted to do two things if that =~ held true? Is that possible? Thanks. - Bryan Bryan Harris wrote: One of my favorite things about perl is that long and tedious solutions can

Elegant sequencing

2004-08-27 Thread Bryan Harris
One of my favorite things about perl is that long and tedious solutions can often be replaced by incredibly elegant and concise ones. I'm writing a sequence generator. I've got most of it handled, but this part bugs me. I want it to take the variable $field containing, e.g.: 4.3:8.3 And

Re: stuck at TRUE/FALSE, pls help

2004-08-14 Thread Bryan Harris
I'm pretty new to CGI programming too, so I probably can't answer your original question, but I would suggest that the first line of your script be: #!/usr/bin/perl -wT The -w turns on warnings if your script does one of a list of things that are screwy, like assigning a variable and never

Re: How to display a Text file using web browser under CGI

2004-08-14 Thread Bryan Harris
Or how about this? use File::Copy; print html\npre\n; copy myfile.txt, \*STDOUT; print /pre\n/html\n; - B Hello! An example would look like this: #!/usr/bin/perl -w use strict; use CGI qw(:standard); my $file_loc = bla; my @file; if (open(FILE, $file_loc)) { @file = FILE;

Sending emails when taint checking is on?

2004-08-13 Thread Bryan Harris
For some reason, when I turn on taint checking, my script dies on the line where I open up sendmail to send an email: ** my ($inOrderTxt) = (param('ordertxt') =~ /([\s!-~]+)/); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =

Re: Dot not string cat?

2004-07-23 Thread Bryan Harris
On Thu, Jul 22, 2004 at 09:58:50PM -0700, Bryan Harris wrote: What's going on here? You need something like $b=${i}_.$j*2; otherwise you are trying to access $i_ Interesting! It seems like I do things like this all the time... How does perl decide where the variable ends

CGI script just stops...

2004-07-22 Thread Bryan Harris
This one baffles me: print p$listfn, I guess we got here./p\n; # write additions to their file open(LISTFILE, $listfn) || print p class=error$listfn could not be written: $!\n; print LISTFILE join(\n, @newlist, ); close(LISTFILE); print pHere too?/p\n; This is part of a CGI script

Dot not string cat?

2004-07-22 Thread Bryan Harris
Does anyone know why this doesn't do what I expect? % perl -e '$i=123.52.32.1; $j=45; $b=$i_.$j*2; print $b, \n;' 90 I'd like it to print: 123.52.32.1_90 What's going on here? TIA. - Bryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Cool construct

2004-07-07 Thread Bryan Harris
I found this construct in the Perl Cookbook: $Current_Screen = param(.State) || Default; I thought it was really cool because if the value of param(.State) comes back undefined, the $Current_Screen variable gets set to Default. So the other day I wanted to do something similar: @somearray =

Cool construct

2004-07-07 Thread Bryan Harris
I found this construct in the Perl Cookbook: $Current_Screen = param(.State) || Default; I thought it was really cool because if the value of param(.State) comes back undefined, the $Current_Screen variable gets set to Default. So the other day I wanted to do something similar: @somearray =

Re: Cool construct

2004-07-07 Thread Bryan Harris
On Tuesday 06 July 2004 23:49, Bryan Harris wrote: I found this construct in the Perl Cookbook: $Current_Screen = param(.State) || Default; I thought it was really cool because if the value of param(.State) comes back undefined, the $Current_Screen variable gets set to Default. So

Process folder structure into new structure

2004-04-26 Thread Bryan Harris
Hi, all, I need to process one folder structure into a new folder structure, e.g. replace the word dog with cat recursively down through a folder, writing the updated files into a new structure: % ls myfolder1 % dog2cat myfolder1 dog2cat: myfolder1 -- myfolder1.cat % ls myfolder1

Re: Process folder structure into new structure

2004-04-26 Thread Bryan Harris
Take a look at Path::Class to manipulate relative paths and File::Path to create complete paths if the don't exist. The code below creates a new absolute path for the source and destination directories and then, within File::Find's Wanted routine, calculates the contents of $File::Find::name

Re: What does this command do: |-

2004-04-25 Thread Bryan Harris
HI, I have started learning PERL recently. I wanted some explaination regarding the following command. open(FILE, |-) Perl implicitly forks a child process. the FILE file handle is opened with write access in the parent process. what the parent process writes to FILE can be read

Re: perl almost an adult? [was: s/// w/o RE]

2004-04-17 Thread Bryan Harris
DO you really think that would be in the documentation? Read 'perlhist': How do you know this? I would never have thought to come up with the 8 letters - perlhist. I just look on the Perl Bookshelf from O'Reilly, but I couldn't find any reference to the birthdate. I think that's

Re: s/// w/o RE

2004-04-15 Thread Bryan Harris
Wiggins So do I after 7 years ;-)... And I after twice that. Hey, perl hasn't been around for quite 21 years! - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response

perl almost an adult? [was: s/// w/o RE]

2004-04-15 Thread Bryan Harris
Wiggins So do I after 7 years ;-)... And I after twice that. Hey, perl hasn't been around for quite 21 years! err, my math must be rusty: twice 7 years != 21 Oops, sorry, my undiagnosed dyslexia is acting up -- I read it three times, and each time it said And I twice after that. Now

s/// w/o RE

2004-04-14 Thread Bryan Harris
A quick question for the wizards-- Is it possible to do a substitution without compiling the pattern at all? ** #!/usr/bin/perl $ss = cool???; $rs = cool.; $_ = Perl is really cool???; s/$ss/$rs/g; print $_\n; ** Thanks!

Re: s/// w/o RE

2004-04-14 Thread Bryan Harris
perldoc perlre for more: \Q quote (disable) pattern metacharacters till \E Wow, there really are wizards here! After 2+ years of perl, I still learn stuff almost every day. I'd never heard of this one before... Thanks all. - Bryan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For

Re: How to determine if STDIN has piped data?

2004-04-01 Thread Bryan Harris
Alternatively, you can use the '-t' operator: exit 0 if -t STDIN I've been waiting for this for a LONG time, thanks Smoot. No problem. It took me a while to find the correct operator as well. Please keep in mind that doing this breaks the de facto Unix standard for filters. A

Re: How to determine if STDIN has piped data?

2004-03-31 Thread Bryan Harris
By the way, what's a socket? Usually, a network protocol end-point which for most I/O purposes looks like a file handle. Instead of reading or writing from a file, the program reads or writes a socket which is typically connected to another program via a network protocol which is either

Re: How to determine if STDIN has piped data?

2004-03-31 Thread Bryan Harris
Bryan Harris wrote: So an example use of a socket would be, say, a script that would listen on a socket (?) and notify me in response to a message from a particular cgi being executed on my webserver? I guess I'm not sure where anyone would use this... A socket or your example? =) I

Re: How to determine if STDIN has piped data?

2004-03-30 Thread Bryan Harris
On Mon, 29 Mar 2004 00:38:50 -0700 Bryan Harris [EMAIL PROTECTED] wrote: Alternatively, you can use the '-t' operator: exit 0 if -t STDIN I've been waiting for this for a LONG time, thanks Smoot. No problem. It took me a while to find the correct operator as well. Please keep

interpolated strings

2004-03-28 Thread Bryan Harris
Is there a way to interpolate strings that the user enters? I'm writing a filter (pipe-cat = pat) that lets you add text to the front or end of some piped data: echo 2 | pat 1 - 3\n The - represents the piped data, so the above should print: % echo 2 | pat 1\n - 3\n 1 2 3 % But here's what

Re: interpolated strings

2004-03-28 Thread Bryan Harris
this because I want to make sure I end with a \n, but I don't want an extra one if one is already there. I guess I could've also done a: $newtxt =~ s/([^\n])$/$1\n/; ... but the above seemed clearer. Is that not a good reason? - B Bryan Harris wrote: Is there a way to interpolate

Re: How to determine if STDIN has piped data?

2004-03-28 Thread Bryan Harris
Alternatively, you can use the '-t' operator: exit 0 if -t STDIN I've been waiting for this for a LONG time, thanks Smoot. - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response

if (!pipe_is_empty) { while() {do_cool_stuff();} }

2004-03-18 Thread Bryan Harris
I have a handy-dandy script that replaces text in files. Very slick: % replace 'dog' 'cat' myfile.txt 1. myfile.txt (1 change) But I'd also like it to be able to act on a pipe if there is one: % cat myfile.txt | replace 'dog' 'cat' My cat has fleas. The problem is I don't want to use the

Re: ENV variables and custom 404 error page

2004-03-02 Thread Bryan Harris
Bryan Harris wrote: # do this. make sure that this line is the # ONLY thing you print out to the browser. print Location: http://rightplace.com/\n\n;; Wow, this is cool! Where is this documented? I'm interested in learning about other things like this... This is part

Re: ENV variables and custom 404 error page

2004-03-01 Thread Bryan Harris
# do this. make sure that this line is the # ONLY thing you print out to the browser. print Location: http://rightplace.com/\n\n;; Wow, this is cool! Where is this documented? I'm interested in learning about other things like this... -- To unsubscribe, e-mail: [EMAIL

Re: Count the number of lines in a file without actually iterating through the file

2004-02-27 Thread Bryan Harris
perl -lpe '}{*_=*.}{' file Ooh, an obfuscated verbose way of writing: perl -lpe'}{$_=$.' file Huh? Could someone explain this? The }{ makes no sense to me... - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

variable FORMAT in printf?

2004-01-19 Thread Bryan Harris
Hi, I've tried everything I can think of, but I feel like a 6th grader trying to solve a 7th grade math problem: I'm trying to build a pretty-fier for any tab-delimited text file (basically space-pad the columns so the decimals line up). I search through the columns finding the longest field

Re: variable FORMAT in printf?

2004-01-19 Thread Bryan Harris
I've tried everything I can think of, but I feel like a 6th grader trying to solve a 7th grade math problem: I'm trying to build a pretty-fier for any tab-delimited text file (basically space-pad the columns so the decimals line up). I search through the columns finding the longest

Re: sorter script [was: Frustrated newbie question]

2003-12-09 Thread Bryan Harris
Bryan Harris wrote: Sometimes perl isn't quite the right tool for the job... % man sort % man uniq If you code it correctly (unlike the program at the URL above) then a perl version will be more efficient and faster than using sort and uniq. Please explain... That's the last

Re: sorter script [was: Frustrated newbie question]

2003-12-08 Thread Bryan Harris
My next Perl task after I get my list of one name per line, is to sort the list and eliminate duplicate names. I have used the following script to sort and remove duplicate entries in flat text files. http://www.downloaddatabase.com/databasesoftware/db-sorter-script.htm Sometimes

Re: sorter script [was: Frustrated newbie question]

2003-12-07 Thread Bryan Harris
My next Perl task after I get my list of one name per line, is to sort the list and eliminate duplicate names. I have used the following script to sort and remove duplicate entries in flat text files. http://www.downloaddatabase.com/databasesoftware/db-sorter-script.htm Sometimes perl

Re: stripping last field of a carriage return

2003-12-07 Thread Bryan Harris
I have tried to strip the carriage return of the last field $field[8] =~ s/\015//g; Uh, isn't the carriage return code 13? - B -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response

Re: Perl Mysql

2003-12-06 Thread Bryan Harris
Which modules i have to install in order to connect perl with mysql ?, in what order ?, My perl installation is on solaris 9. I already have mysql installed. Thanks for the help. Here's what I wrote up while installing under OS X, should be pretty similar: To install perl support for

Re: buffered output?

2003-11-21 Thread Bryan Harris
The problem is, the output of motuds is not getting written out to the file immediately. Somehow it's getting cached somewhere, and only gets written out once in a while. If I type that command on the command line, the tail command works properly. So something with the exec process is

buffered output?

2003-11-20 Thread Bryan Harris
I have an odd problem... I have a perl script that execs another program: $cmd = motuds t1.dat t2.dat t3.dat out1; exec $cmd; Motuds takes awhile to run, though, and I often want to see how it's doing: % tail -f out1 The problem is, the output of motuds is not getting written out to the

connecting to mysql for the first time

2003-10-31 Thread Bryan Harris
I've been enjoying perl for almost 2 years now, and I think I'm ready to step into interacting with a database. (big step!) I have mysql, and I have some simple tables. Now I want to be able to access those tables from perl. Can anyone offer a simple tutorial on how to do this? Thanks!!! -

Re: connecting to mysql for the first time

2003-10-31 Thread Bryan Harris
A good resource was perldoc DBD::mysql and perldoc DBI I apparently don't have those modules... 1% perldoc DBD::mysql No documentation found for DBD::mysql. 2% perldoc DBI No documentation found for DBI. I've never installed a module before, does that signal I'm in over my head? Where would

Re: connecting to mysql for the first time

2003-10-31 Thread Bryan Harris
When perl wants to connect to databases (any database) perl uses a database driver. This db driver is called DBI. Each DBI has an interface to each vendors database called the DBD modules. So depending on the kind of database you are planning to use, you will HAVE to install 1) DBI 2) DBD

Re: easiest `cat` in perl

2003-10-04 Thread Bryan Harris
And what is the T in -Tw? That doesn't appear to show up in the man page... T means tainted. It's what you want to run on all code in your cgi-bin directory so that a hacker can't r00t your box. Basically it prevents your perl script from doing anything dumb. Out of curiousity, is

Re: easiest `cat` in perl

2003-10-03 Thread Bryan Harris
use File::Copy; copy header.incl, \*STDOUT; I like this, it's very clean. Unfortunately I'm having trouble using it in a cgi script... ** #!/usr/bin/perl -w use File::Copy; print Content-type: text/plain\n\n; copy header.incl, \*STDOUT; print More stuff

Re: easiest `cat` in perl

2003-10-03 Thread Bryan Harris
Ahh. A buffering issue. Your content-type: is not appearing before the header.incl. You need to add $| = 1; before the print. That's the reason I start nearly all my CGI scripts with: #!/usr/bin/perl -Tw use strict; $|++; so that I don't ever have to worry about

  1   2   >