Re: regexp to replace double with single quotes inside html tags
John, can you explain the piece of code that you wrote. Thanks and happy new year :-) - Original Message - From: "John W. Krahn" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, December 30, 2001 3:38 AM Subject: Re: regexp to replace double with single quotes inside html tags > Birgit Kellner wrote: > > > > I would like to replace all double with single quotes inside a html tag, > > i.e. perform the substitution only for html tag attributes, but not outside > > tag boundaries. > > > > my $string = qq|http://someurl.url"; title="welrkwlekrj">aha, > > and here "follows" a > > quoted expression: "blabla"http://someimage.gif"; width="80" > > height="200">|; > > > > All double quotes should be replaced by single ones except those > > surrounding the string "blabla". > > > > My approach would be: > > Look for <, followed by a string of characters except >, followed by" - if > > matched, replace this instance of " with '. > > > > I found the following code to work, but it strikes me as very clumsy and I > > am not sure whether it captures all relevant cases and really excludes all > > those which are not relevant. > > > > while ($string =~ /(<[^>]*?)"/gs) { > > my $var = $1; > > $string =~ s/$var"/$var'/;} > > > > print qq|$string\n|; > > > $string =~ s/(<[^>]+>)/$a=$1;$a=~tr|"|'|;$a/eg; > > > John > -- > use Perl; > program > fulfillment > > -- > 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]
Newbie - #include virtual in my .SHTML file just displays the contents of the CGI
If I run the script from my browser, it works great. When I call the CGI file from my SHTML file, it just dumps all of the text from the CGI file into the brower. Here is a simple example: -MY.SHTML -MY.CGI #!/usr/bin/perl print "content-type:text/html\n\n"; print "This is BOLD"; print "This is not."; THE OUTPUT WHEN CALLED FROM .SHMTL #!/usr/bin/perl print "Content-type:text/html\n\n"; print ""; print "This is BOLD"; print ""; print " This is not."; ...also, I tried to use: , and I get a string of text printed at the top: (something like...) HTTP: 1/1 DATE: (date) TIME: (time) IIS 5.0 blah blah blah. I'm sure this is something simple, but I can't seem to find the answer. Thanks in advance. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp to replace double with single quotes inside html tags
Nestor Florez wrote: > > From: "John W. Krahn" <[EMAIL PROTECTED]> > > > Birgit Kellner wrote: > > > > > > while ($string =~ /(<[^>]*?)"/gs) { > > > my $var = $1; > > > $string =~ s/$var"/$var'/;} > > > > > > print qq|$string\n|; > > > > $string =~ s/(<[^>]+>)/$a=$1;$a=~tr|"|'|;$a/eg; > > can you explain the piece of code that you wrote. Here is the verbose version. $string =~ s{# start regular expression ( # start capture <# match a less-than symbol [^>]+# match one or more characters not a greater-than symbol ># match a greater-than symbol ) # end capture } {# start replacement expression $a = $1; # can't modify $1 so copy it $a =~ tr|"|'|; # replace double quotes with single quotes $a # use this new string to replace the old one }gex;# g = global pattern match # e = evaluate the replacement expression # x = allow whitespace and comments John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Would anybody tell me what is the meaning of "foo" ?
A related term of pretty much the same parentage is SNAFU Situation Normal All Fouled Up I am pretty sure both terms originated during WWII. -Original Message- From: Matt C. [mailto:[EMAIL PROTECTED]] Sent: Sunday, December 30, 2001 7:22 PM To: [EMAIL PROTECTED] Subject: Re: Would anybody tell me what is the meaning of "foo" ? Here's my understanding, pretty sure I am very close, if not correct. Foo and Bar are parts of a miliary acronym (or at least that is my understanding of its origin), FooBar. Sometimes called FuBar. They stand for: 1) Fouled up beyond all recognition (family version) - or - 2) F*** up beyond all recognition So it's a cute term to play around with as a neophyte, as your code will sometimes be foobar. Matt --- Connie Chan <[EMAIL PROTECTED]> wrote: > Thank you Eric and Peter. but.. I still don't understand.. > What is the meaning of foo in perl programming ? I see quite a lot of > sample codes use foo. besides, and what is bar ? Is that a certain > type of variable ?? just like a number or something like escape char > ?? Please tell me more.. > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- 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: Newbie - #include virtual in my .SHTML file just displays the contents of the CGI
Dale W wrote: > > If I run the script from my browser, it works great. When I call the CGI > file from my SHTML file, it just dumps all of the text from the CGI file > into the brower. Here is a simple example: > > -MY.SHTML > I don't know something about "virtual" scripts. However, > > -MY.CGI > #!/usr/bin/perl > print "content-type:text/html\n\n"; ^ ^^ The standard way is to write print "Content-Type: text/html\n\n"; > > print "This is BOLD"; > print "This is not."; > > ... Best Wishes, Andrea -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Making Cygwin and Apache and Perl Play Nice
Hello Richard, Monday, December 31, 2001, Richard S. Crawford <[EMAIL PROTECTED]> wrote: RSC> Here's the problem. When I run Perl scripts under win2k, I have to include RSC> this as the first line of each CGI script: RSC> #! c:/perl/bin/Perl.exe RSC> But when I run them under Linux, I have to include this: RSC> #!/usr/bin/perl RSC> Is there any way that anyone knows of to map my Perl interpreter under RSC> Windows to the Cygwin installation, so that I don't have to change the RSC> first line of my Perl CGI scripts when I switch operating systems? sure, use cygwin's mount. C:\>mount Device Directory Type Flags D:\CYGNUS\USR /usruser textmode C: / user textmode C:\>ls /usr BIN INCLUDE LIB LOCALSBIN DOC INFO LIBEXEC MAN SHARE RSC> Is this RSC> something I can change under Apache (I'm running 1.3)? hmmm... no. Best wishes, Maximmailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: child processes and environment variables
cant control it ... my company appends it to all messages sent from the company sorry -Original Message- From: Andrea Holstein [mailto:[EMAIL PROTECTED]] Sent: Saturday, December 29, 2001 9:01 AM To: [EMAIL PROTECTED] Subject: Re: child processes and environment variables Thomas Maciejewski wrote: > > -- > This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. I don't want to be a policeman :-). But the signature statement should be less than 4 lines. So nearly 50% of your messages consists of the not so important signature statement. Please don't force all other users to download unnecessary data. Try to shorten it, and if it's impossible use a free mailer. And again the statement does not stand for what this Perl-Newsgroup stands for. Greetings, Andrea -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Reidrecting STDOUT to an already open filehandle
I am developing a script that is being used in a data warehousing environment on an NT server. I am logging the script's activity (log & err) in files under a folder specific to each multidimensional cube that is processed. Multiple instances of this script can be running concurrently because I process numerous different cubes.I have opened my log file as follows: use strict; use warnings; ... ... # path & name of $stdout & $stderr constructed use IO::File; my $stdout_fh = IO::File->new( "> $stdout" ); my $stderr_fh = IO::File->new( "> $stderr" ); Later on in the script I use the "system" command to run a batch file of Cognos commands I have generated on the fly to "do a bunch of stuff" to the Cognos application hosting these cubes. I want all the activity being performed by the batch file of Cognos commands to be logged in my cube specific file I have open. But now, it goes to STDOUT - which is the screen because I have not redirected it. How do I get STDOUT to append (>>) to the file I am writing to with "print $stdout_fh". Thanks - rwb __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
move
I'm sure this is a dumb question. It seems like one anyways. Is there a move command in perl? I know I can copy then unlink a file but I cant find a move (or similar) command. -Michael __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: move
I think the rename function is what you're looking for: rename "old", "new"; -Original Message- From: Michael McQuarrie [mailto:[EMAIL PROTECTED]] Sent: Monday, December 31, 2001 10:51 AM To: [EMAIL PROTECTED] Subject: move I'm sure this is a dumb question. It seems like one anyways. Is there a move command in perl? I know I can copy then unlink a file but I cant find a move (or similar) command. -Michael __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- 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: move
system("mv", "/dir/file", "/dir2/file"); > -Original Message- > From: Michael McQuarrie [mailto:[EMAIL PROTECTED]] > Sent: Monday, December 31, 2001 10:51 AM > To: [EMAIL PROTECTED] > Subject: move > > > I'm sure this is a dumb question. It seems like one anyways. > Is there a move command in perl? I > know I can copy then unlink a file but I cant find a move (or > similar) command. > > -Michael > > __ > Do You Yahoo!? > Send your FREE holiday greetings online! > http://greetings.yahoo.com > > -- > 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: move
I think 'system("mv", "/dir/file", "/dir2/file");', will only work if you have access to unix functions. system("mv", "/dir/file", "/dir2/file"); > -Original Message- > From: Michael McQuarrie [mailto:[EMAIL PROTECTED]] > Sent: Monday, December 31, 2001 10:51 AM > To: [EMAIL PROTECTED] > Subject: move > > > I'm sure this is a dumb question. It seems like one anyways. > Is there a move command in perl? I > know I can copy then unlink a file but I cant find a move (or > similar) command. > > -Michael > > __ > Do You Yahoo!? > Send your FREE holiday greetings online! > http://greetings.yahoo.com > > -- > 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: move
yes will work in win32 as well. I guess 'rename' would be better, avoids usig shell function call. > -Original Message- > From: McCollum, Frank [mailto:[EMAIL PROTECTED]] > Sent: Monday, December 31, 2001 11:03 AM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: RE: move > > > I think 'system("mv", "/dir/file", "/dir2/file");', will only > work if you > have access to unix functions. > > > system("mv", "/dir/file", "/dir2/file"); > > > -Original Message- > > From: Michael McQuarrie [mailto:[EMAIL PROTECTED]] > > Sent: Monday, December 31, 2001 10:51 AM > > To: [EMAIL PROTECTED] > > Subject: move > > > > > > I'm sure this is a dumb question. It seems like one anyways. > > Is there a move command in perl? I > > know I can copy then unlink a file but I cant find a move (or > > similar) command. > > > > -Michael > > > > __ > > Do You Yahoo!? > > Send your FREE holiday greetings online! > > http://greetings.yahoo.com > > > > -- > > 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: move
The File::Copy module provides two basic functions, copy and move, which are useful for getting the contents of a file from one place to another. - Original Message - From: "Michael McQuarrie" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, December 31, 2001 3:51 PM Subject: move > I'm sure this is a dumb question. It seems like one anyways. Is there a move command in perl? I > know I can copy then unlink a file but I cant find a move (or similar) command. > > -Michael > > __ > Do You Yahoo!? > Send your FREE holiday greetings online! > http://greetings.yahoo.com > > -- > 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 All: move
Thanks for all your help. --- Michael McQuarrie <[EMAIL PROTECTED]> wrote: > I'm sure this is a dumb question. It seems like one anyways. Is there a move >command in perl? > I > know I can copy then unlink a file but I cant find a move (or similar) command. > > -Michael > > __ > Do You Yahoo!? > Send your FREE holiday greetings online! > http://greetings.yahoo.com > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
question -- beginner's programmer's block
Hello - I am trying to figure out how to convert an output file to a comma separated values file. The original file is of this form: * foo *** thingA: 12 thingB: 23 thingC: 21 trial 1 = colAcolBcolCcolD 1 23 28 273 227 2 237 232711 1 3 0 10 22 0 4 2 3 38 2 .etc trial 2 etc. My dilemma so basic - I know that when I open this file as I can cycle through this program as While but when I do this I have to cycle through everything at once and have a bunch of conditional statements. To get around this, my idea is to have a main loop with two subroutines: say FooSub and TrialSub. For the first I would split on ':' for the next I would split on '\s+'. But how do I skip a line? I want to get past the . . . line but if I use next to start the subroutine won't that create a loop that reads no lines - perhaps an ((if $_ !~ /^\*{1,5}/) {skip} would be best and just have each module end when it hits an '='. Can someone give me basic advice if I am going about this in the correct direction? I feel like I need a little nudge in the right direction before I try to make a potentially broken idea work. Thanks, Tim Timothy B Booher, Lt USAF, AFRL/MNAC 101 West Eglin Blvd, Suite 339 Eglin AFB FL 32542-6810 Phone: 850-882-8302 Ext. 3360 (DSN 872-) FAX: 850-882-2201
RE: question -- beginner's programmer's block
I'm not sure that I completely understand, so this may or may not help. Anyway, I hope it does. If I understand correctly you want to grab each section and pass it to the appropriate sub for processing. There are lots of ways to do this, but this way came to mind first. It all works around a buffer and a state. When the *** line is seen the state is set to 1, when the line is seen the state is set to 2. When one of these is seen it executes the dispatch() sub to determine which sub should process the *LAST* sub seen. If the current line is not one of those section headers it buffers the line. So it will run something like this... >>* foo *** 1. run dispatch() sending the inital state of 0 (which will do nothing). set state to 1, go to next line. >> thingA: 12 2. buffer line >> thingB: 23 3. buffer line >> thingC: 21 4. buffer line trial 1 = 5. run dispatch() with a state of 1 and send the buffer (which passes the buffer to fooSub()). set state to 2, clear the buffer, and go to the next line. >> 6. buffer line >> colAcolBcolCcolD 7. buffer line >>1 23 28 273 227 8 buffer line >> 2 237 232711 1 9. buffer line >>trial 2 10. run dispatch() with a state of 2 and send the buffer (which passes the buffer to trialSub()). set state to 2, clear the buffer, and go to the next line. etc, etc... The last dispatch() is called after the loop to process the last section to the end of file. # UNTESTED my $state = 0; my $buffer = ''; while (my $line = ) { if ( $line =~ /^\*+/ ) { # this is the *** line dispatch($state, $buffer); # clear the buffer, set the new state # and go to the next line. $buffer = ''; $state = 1; next; } elsif ( $line =~ /^=+/ ) { # this is a "trail" line dispatch($state, $buffer); # clear the buffer, set the new state # and go to the next line. $buffer = ''; $state = 2; next; } # buffer the line $buffer .= $line; } # run the last section dispatch($state, $buffer); sub dispatch { my ($state, $buffer) = @_; # skip begining of file to first section return unless ( $state ); if ( $state == 1 ) { fooSub($buffer); } elsif ( $state == 2 ) { trialSub($buffer); } } sub fooSub { # do stuff} sub trialSub { # do stuff } -Original Message- From: Booher Timothy B 1stLt AFRL/MNAC [mailto:[EMAIL PROTECTED]] Sent: Monday, December 31, 2001 1:44 PM To: [EMAIL PROTECTED] Subject: question -- beginner's programmer's block Hello - I am trying to figure out how to convert an output file to a comma separated values file. The original file is of this form: * foo *** thingA: 12 thingB: 23 thingC: 21 trial 1 = colAcolBcolCcolD 1 23 28 273 227 2 237 232711 1 3 0 10 22 0 4 2 3 38 2 .etc trial 2 etc. My dilemma so basic - I know that when I open this file as I can cycle through this program as While but when I do this I have to cycle through everything at once and have a bunch of conditional statements. To get around this, my idea is to have a main loop with two subroutines: say FooSub and TrialSub. For the first I would split on ':' for the next I would split on '\s+'. But how do I skip a line? I want to get past the . . . line but if I use next to start the subroutine won't that create a loop that reads no lines - perhaps an ((if $_ !~ /^\*{1,5}/) {skip} would be best and just have each module end when it hits an '='. Can someone give me basic advice if I am going about this in the correct direction? I feel like I need a little nudge in the right direction before I try to make a potentially broken idea work. Thanks, Tim Timothy B Booher, Lt USAF, AFRL/MNAC 101 West Eglin Blvd, Suite 339 Eglin AFB FL 32542-6810 Phone: 850-882-8302 Ext. 3360 (DSN 872-) FAX: 850-882-2201 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Making a phone call
Hi friends. I am looking for a module to make a phone call, please tell me if you know one. Bye and Thanks a lot. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Left side variable interpolation during associative arrayassignment?
I am trying to build up associative arrays using a looping draw from a database. I would like to end up with one or more arrays(depending on number of elements in the @Dataset) named %sub0, %sub1, %sub2... and so on. I need to keep these arrays around for latter manipulation. What I have now is: $c=0; foreach (@Datasets){ my $SQL = "select year,value from data where trend like '%$Datasets[$c]%' order by year"; my $arrayname = "\$sub$c"; my $cursor = $dbh->prepare($SQL); $cursor->execute; while(@columns = $cursor->fetchrow){ $arrayname{$columns[0]} = $columns[1]; #FAILED LEFT SIDE INTERPOLATION } # end while assignment $c++; } However, what obviously is happening is that $arrayname{columns[0]} = $columns[1] is sticking the values into an array called "$arrayname" rather than interpolating back to "$sub0" (or "sub1"... depending on what loop we are in). I've tried various conbinations of quotation marks and eval statements to try to make this work with no luck. Can this be done? If not, is there a standard workaround? Many thanks for any assistance. Andrew Koebrick Web Coordinator/Librarian MN-Planning (Office of Strategic and Long Range Planning) 658 Cedar St., Suite 300 St. Paul, MN 55155 651-296-4156 phone 651-296-3698 fax www.mnplan.state.mn.us -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to create an object with perl ?
an alternative might be a beginners tutorial to OO programming in perl that i wrote... check it out here: http://www.japh.nu/index.cgi?base=tuts hth, jos Quoting Peter Cornelius <[EMAIL PROTECTED]>: > There's some great documentation on this. Check out 'perldoc perltoot' > on > your local command line or > http://www.perldoc.com/perl5.6.1/pod/perltoot.html if you're into that > "web" > thing. > > Here's my hello world class > > package Hello; #A package declaration starts a class > > #A method to create a new instance of my class > sub new { > my ($class, $message) = @_; > > my %hash; > $hash{message} = $message; > > return bless \%hash, $class; #An object is a blessed reference. > } > > #Some silly method > sub sayit { > my $self = shift; > print "Hello $self->{message}\n"; > } > > package main; #now switch to the main package > # if you had the Hello class in a separate file called Hello.pm you > would > need to 'use Hello;' here > > #instantiate my class > my $hello = new Hello ("World"); > > #invoke my method > $hello->sayit(); > > > Of course, this example is lame, but simple. Take a look at the above > documentation for more explanations and details. If you like the book > thing > check out Damian Conway's "Object Oriented Perl" for more than you ever > wanted to know. > > Peter C. > > > -Original Message- > From: Connie Chan [mailto:[EMAIL PROTECTED]] > Sent: Sunday, December 30, 2001 9:56 AM > To: [EMAIL PROTECTED] > Subject: How to create an object with perl ? > > > I only know how to use simple hash to carry pairs of data, however, > Would anybody could tell how can I create a new object in perl ? > and how can I call a property's value ? Any very simple live example ? > > Have a nice day to you all =) > > > -- > 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: Left side variable interpolation during associative array assignment?
Well I'm not sure why you would want to do it that way, but it can be done... ${$arrayname}{$columns[0]} = $columns[1]; You may be better off with an array of hashes... my @data = (); while( my @columns = $cursor->fetchrow ) { my %tmp = () $tmp{$columns[0]} = $columns[1]; push @data, \%tmp; # push the hash on to the array } Then later... foreach my $item ( @data ) { # dereference and use as a hash again my %tmp = %{$item}; } I have always found that it is better to use references than building variable names on the fly... unless of course there is a good reason what they can't be done. Rob -Original Message- From: Andrew Koebrick [mailto:[EMAIL PROTECTED]] Sent: Monday, December 31, 2001 4:02 PM To: [EMAIL PROTECTED] Subject: Left side variable interpolation during associative array assignment? I am trying to build up associative arrays using a looping draw from a database. I would like to end up with one or more arrays(depending on number of elements in the @Dataset) named %sub0, %sub1, %sub2... and so on. I need to keep these arrays around for latter manipulation. What I have now is: $c=0; foreach (@Datasets){ my $SQL = "select year,value from data where trend like '%$Datasets[$c]%' order by year"; my $arrayname = "\$sub$c"; my $cursor = $dbh->prepare($SQL); $cursor->execute; while(@columns = $cursor->fetchrow){ $arrayname{$columns[0]} = $columns[1]; #FAILED LEFT SIDE INTERPOLATION } # end while assignment $c++; } However, what obviously is happening is that $arrayname{columns[0]} = $columns[1] is sticking the values into an array called "$arrayname" rather than interpolating back to "$sub0" (or "sub1"... depending on what loop we are in). I've tried various conbinations of quotation marks and eval statements to try to make this work with no luck. Can this be done? If not, is there a standard workaround? Many thanks for any assistance. Andrew Koebrick Web Coordinator/Librarian MN-Planning (Office of Strategic and Long Range Planning) 658 Cedar St., Suite 300 St. Paul, MN 55155 651-296-4156 phone 651-296-3698 fax www.mnplan.state.mn.us -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
add text to the end of a word. HELP!!
Hi I need to add a word to the end of a word inside a file. HELP PLEASE for example: I will read a file with these names july tony richard then I want to add the following to the name @minime.com. So it will look like [EMAIL PROTECTED] = Peter Lemus UNIX/NT Networks Engineer [EMAIL PROTECTED] --The universe is way too big for us to be alone; the real question is; who is out-there, besides us "humans"? --A wise man will be master of his mind, a fool will be its slave. Dr.David Schwartz. --Enjoy every moment of the day; Live like as if today was your last day alive, and perhaps, it might be. __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Rex Swain's HTTP Viewer
Cool... http://www.rexswain.com/httpview.html -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Left side variable interpolation during associative array assignment?
Before I point to the problem here, let me point out that you are trying to use symbolic references which will severely decrease the readability of your code. I personally believe that symbolic references are one of the many forms of evil perl which, while appearing elegant, merely lure you into the mire of obfuscation. If you need a named list of arrays you should probably be using a hash. The keys can be generated in the same way but are bound to the data structure (ie, you can find out what they are with keys() instead of having to know the secret formula). Stay away from symbolic references, they don't work with 'use strict;' anyway. That should tell you something. So what's happening here is that you assign a string to the lexical variable $arrayname and then *overwrite* this with the hash arrayname. You don't dereference the symbolic reference so it uses the variable name 'arrayname' instead of the dynamic name you generated. If you just add another '$' in front, it should work the way want. You might want to do '${$arrayname}{$column[0]}' to at least alert the reader of the code that something weird is going on here. Good Luck, Peter C. On Monday, December 31, 2001, at 01:01 PM, Andrew Koebrick wrote: > I am trying to build up associative arrays using a looping draw from a > database. I would like to end up with one or more arrays(depending on > number of elements in the @Dataset) named %sub0, %sub1, %sub2... and so > on. I need to keep these arrays around for latter manipulation. > > What I have now is: > > $c=0; > foreach (@Datasets){ > my $SQL = "select year,value from data where trend like > '%$Datasets[$c]%' order by year"; > my $arrayname = "\$sub$c"; > my $cursor = $dbh->prepare($SQL); > $cursor->execute; > while(@columns = $cursor->fetchrow){ > $arrayname{$columns[0]} = $columns[1]; #FAILED LEFT SIDE > INTERPOLATION > } # end while assignment > $c++; > } > > However, what obviously is happening is that $arrayname{columns[0]} = > $columns[1] is sticking the values into an array called "$arrayname" > rather than interpolating back to "$sub0" (or "sub1"... depending on > what loop we are in). I've tried various conbinations of quotation > marks and eval statements to try to make this work with no luck. Can > this be done? If not, is there a standard workaround? > > Many thanks for any assistance. > > Andrew Koebrick > Web Coordinator/Librarian > MN-Planning (Office of Strategic and Long Range Planning) > 658 Cedar St., Suite 300 > St. Paul, MN 55155 > > 651-296-4156 phone > 651-296-3698 fax > > www.mnplan.state.mn.us > > > > -- > 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: add text to the end of a word. HELP!!
Wow! Your question sounds really urgent. Did you get talked into converting a contact database into a bulk email sender? I hate when that happens. Whether or not that's what you're doing, this should help: $email = $name . '@minime.com'; # i'm pretty sure this works Look up the '.' (dot) operator in your perl documentation for more details. -- Brad > Hi I need to add a word to the end of a word inside a > file. > > HELP PLEASE > > for example: I will read a file with these names > july > tony > richard > > then I want to add the following to the name > @minime.com. So it will look like [EMAIL PROTECTED] > > = > Peter Lemus > UNIX/NT Networks Engineer > [EMAIL PROTECTED] > > --The universe is way too big for us to be alone; the real question is; who is out-there, besides us "humans"? > --A wise man will be master of his mind, a fool will be its slave. Dr.David Schwartz. > --Enjoy every moment of the day; Live like as if today was your last day alive, and perhaps, it might be. > > __ > Do You Yahoo!? > Send your FREE holiday greetings online! > http://greetings.yahoo.com > > -- > 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: add text to the end of a word. HELP!!
Peter Lemus wrote: > > Hi I need to add a word to the end of a word inside a > file. > > for example: I will read a file with these names > july > tony > richard > > then I want to add the following to the name > @minime.com. So it will look like [EMAIL PROTECTED] perl -pli -e's/$/\@minime.com/' yourfile.txt John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: add text to the end of a word. HELP!!
Assume that $file is the names file that you have. !/usr/bin/perl -w $file = qq(./file); $newfile = qq(./newfile); open FILE, "$file" or die "Cannot open file $file: $!\n"; open INFILE, ">$newfile" or die "Cannot open file $newfile: $!\n"; while () { chomp($_); s/(.*)/$1\@feathertrip\.net/i; print INFILE "$_\n"; } close(FILE); close(INFILE); You can add an ulink and rename directive to this to get it back to the original file name -James > Hi I need to add a word to the end of a word inside a > file. > > HELP PLEASE > > for example: I will read a file with these names > july > tony > richard > > then I want to add the following to the name > @minime.com. So it will look like [EMAIL PROTECTED] > > = > Peter Lemus > UNIX/NT Networks Engineer > [EMAIL PROTECTED] > > --The universe is way too big for us to be alone; the real question is; who is out-there, besides us "humans"? > --A wise man will be master of his mind, a fool will be its slave. Dr.David Schwartz. > --Enjoy every moment of the day; Live like as if today was your last day alive, and perhaps, it might be. > > __ > Do You Yahoo!? > Send your FREE holiday greetings online! > http://greetings.yahoo.com > > -- > 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]
perl on Mac OSX
I am not sure whether this is a perl question or a Mac question, but I haven't found a good OSX list yet so please bear with me. I have tried to find the answer in "Learning Perl", "Programming Perl", and the "Perl Cookbook" without success. I write the scripts exactly the same as I do on a Linux box, chmod a+x the file and try to run them. They don't run. Do I need to use an extension like .plx or something? TIA John _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: add text to the end of a word. HELP!!
- Original Message - From: "Peter Lemus" <[EMAIL PROTECTED]> > Hi I need to add a word to the end of a word inside a > file. > > HELP PLEASE > > for example: I will read a file with these names > july > tony > richard > > then I want to add the following to the name > @minime.com. So it will look like [EMAIL PROTECTED] There are many ways to do it. Some would use regexes or map. Anyway heres one solution assuming your file contain only 1 word in one line.. open FILE, 'yourfile.txt' or die "$!\n"; while (){ chomp; $_ = "$_\@minime.com"; print "$_\n"; }; close FILE; _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: perl on Mac OSX
What if you try this %perl filename.pl If this runs then it just means that your path_to_perl is wrong on your shebang line. Happy New Year all!! -Original Message- From: John Gilger [mailto:[EMAIL PROTECTED]] Sent: Monday, December 31, 2001 6:27 PM To: [EMAIL PROTECTED] Subject: perl on Mac OSX I am not sure whether this is a perl question or a Mac question, but I haven't found a good OSX list yet so please bear with me. I have tried to find the answer in "Learning Perl", "Programming Perl", and the "Perl Cookbook" without success. I write the scripts exactly the same as I do on a Linux box, chmod a+x the file and try to run them. They don't run. Do I need to use an extension like .plx or something? TIA John _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- 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: add text to the end of a word. HELP!!
- Original Message - From: "Ahmed Moustafa" <[EMAIL PROTECTED]> Newsgroups: perl.beginners To: "Leon" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> > Can you open a file for reading and writing as the same time? I have asked the question of can I read and write to the same file simultaneously, such as this :- open FILE, 'myfile.txt' or die "$!\n"; open FILE2, '>myfile.txt' or die "$!\n"; while (){ # do some changes to $_; print FILE2 $_; }; but I did not get any response. Therefore I dont think we can do that. end of msg - > Leon wrote: > > > There are many ways to do it. Some would use regexes or map. Anyway heres > > one solution assuming your file contain only 1 word in one line.. > > > > open FILE, 'yourfile.txt' or die "$!\n"; > > while (){ > > chomp; > > $_ = "$_\@minime.com"; > > print "$_\n"; > > }; > > close FILE; > _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]