Re: Modules inter-relay ?
On 12/4/06, Mug [EMAIL PROTECTED] wrote: BEGIN { unshift (@INC, /special); unshift (@INC, /special/packages); } use strict; use InitGlobal; And if I didn't get mis-understood on what I've studied, 'use' still comes earlier than 'BEGIN{}', so what is the mystery why this method can do that ? In this particular case BEGIN comes first and simply tells Perl to look at /special and /special/packages BEFORE looking anywhere else for the packages you wish to use in your various projects. You still need to make sure the proper functions/sub-routines are exported so that your code is called in preference over the Perl code. However, if you wish to control what is required -- say branch logic, you will need to stick with te 'require' directive as use packages referenced will always be brought in even if they are not called. HTH/-Sx- -- WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/ -- 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!, while extending scalar with vec()
On Sun, Dec 03, 2006 at 02:47:33AM -0800, kyle cronan wrote: Hi, I was wondering if anyone can help me figure out a problem having to do with accessing a scalar variable with vec().. it's illustrated by this little test program: #!/usr/bin/perl my $foo = ''; vec($foo, (1$ARGV[0])-1, 8)=1; I can run this with the argument 27, and it works just fine. Perl uses a bit more than 128 MB virtual memory before exiting, just as one would expect. When I run the program with n=28 (perl 5.8.8, linux), I get: Out of memory! I have plenty of virtual memory, so there's no reason a malloc would fail that I can think of. From looking at perldebguts and malloc.c in the source, it looks like sbrk is also used (is this just for package globals?), so I tried using a lexical variable and I tried getting a reference to an anonymous scalar with $vec = *foo{SCALAR} then extending $$vec, but the same thing happened. I can create a string of the same size using something like 'chr(0) x (1$ARGV[0])', and perl will happily create a character array of length 2^28 (and use half a gig to do so of course ;). But even if I extend the scalar to the correct length in this fashion, I still get fatal errors when trying to write into it with vec(). Then I thought maybe there's something like a maximum bucket size in the perl allocator, which vec() lvalues don't handle properly, so I tried compiling perl with -DNO_FANCY_MALLOC and -DPLAIN_MALLOC. I still get the same error. I don't understand why a 128 MB scalar string is no problem but 256 MB causes this? I've noticed that with perl 5.8.6 I get the error panic: realloc at Perhaps it's the same error condition described more accurately? But according to perldiag, this is an internal error that indicates something tried to allocate a negative number of bytes! Should I submit this with perlbug? You've found a bug in the vec code. You can probably imagine that the code is pretty fiddly in that area. I've had a poke around and can see a few problems but I'm probably not going to have time to look further this week. So yes, a perlbug report is in order. You are correct with your analysis of the panic: realloc error. You must have your 5.8.6 built with -DDEBUGGING, since that is when you will see this message. In this case, a negative number of bytes really means when the top bit is set, so = 2**31 will also fail this test, which is what is happening in this case. This is a fundamental limit (pretty much) unless you move to 64 bits. In the report it might be helpful to note the following cases, run with the latest development source: $ perl5.9.5 -e 'vec($x, (131) - 1, 1) = 1' panic: realloc at -e line 1. $ perl5.9.5 -e 'vec($x, (131) - 1, 2)' segmentation fault $ gdb ./perl (gdb) run -e 'vec($x, (131) - 1, 2)' Starting program: /home/pjcj/g/perl/bleadperl/perl -e 'vec($x, (131) - 1, 2)' Program received signal SIGSEGV, Segmentation fault. 0x081aede8 in Perl_do_vecget (sv=0x82b1cc0, offset=2147483647, size=2) at doop.c:825 825 retnum = (s[uoffset 3] (uoffset 7)) ((1 size) - 1); (gdb) where #0 0x081aede8 in Perl_do_vecget (sv=0x82b1cc0, offset=2147483647, size=2) at doop.c:825 #1 0x08157156 in Perl_pp_vec () at pp.c:3182 #2 0x080b6474 in Perl_runops_debug () at dump.c:1908 #3 0x080e5980 in S_run_body (oldscope=1) at perl.c:2404 #4 0x080e4f5c in perl_run (my_perl=0x829d008) at perl.c:2324 #5 0x0805e951 in main (argc=3, argv=0xb174, env=0xb184) at perlmain.c:113 (gdb) It may be that the solution ends up being, at least in part, that we do better input validation, since vec($x, (136) - 1, 1) = 1; probably isn't doing what the author expected anyway. If you would prefer I'd be happy to send the report, but I don't want to send a duplicate, so let me know. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
I'd like to work
I was thinking about a Perl project (may be more)there I could work, gain experience, and probably make something usefull for society. I am a begginer in Perl, also can work with Tk CGI and DBI. If u could do smth about that I'd be very thankfull. -- Thanks, Monomachus Don't worry, Be Happy -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
I'd like to work
I was thinking about a Perl project (may be more) there I could work (for free - 10$ per month), gain experience, and probably make something usefull for society. I am a begginer in Perl, also can work with Tk CGI and DBI. If u could do smth about that I'd be very thankfull. -- Thanks, Monomachus Don't worry, Be Happy -- 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 Query - Conversion of EXE file
From: Dharshana Eswaran [EMAIL PROTECTED] Hi Randal, I am trying to generate an exe file from few perl programs. I have 4 files which are main.pl, subroutine1.pl, subroutine2.pl and subroutine3.pl. main.pl file is the main program and it depends on the other subroutine files for data. So i tried zipping it using winzip and ran pp -o foldername.exe foldername.zip the exe file gets created as foldername.exe but when i tried runing it , it flags an error saying Usage: D:\Perl\foldername.exe script_file_name. Can i know how to create the EXE file with all the files together? Thanks and Regards, Dharshana You are making it harder for yourself than you have to. Don't ZIP anything ... pp -o main.exe main.pl should be enough. And if the pp doesn't notice your main.pl uses subroutineX.pl then try pp -o main.exe main.pl subroutine*.pl Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- 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 Query - Conversion of EXE file
On 12/4/06, Jenda Krynicky [EMAIL PROTECTED] wrote: From: Dharshana Eswaran [EMAIL PROTECTED] Hi Randal, I am trying to generate an exe file from few perl programs. I have 4 files which are main.pl, subroutine1.pl, subroutine2.pl and subroutine3.pl. main.pl file is the main program and it depends on the other subroutine files for data. So i tried zipping it using winzip and ran pp -o foldername.exe foldername.zip the exe file gets created as foldername.exe but when i tried runing it , it flags an error saying Usage: D:\Perl\foldername.exe script_file_name. Can i know how to create the EXE file with all the files together? Thanks and Regards, Dharshana You are making it harder for yourself than you have to. Don't ZIP anything ... pp -o main.exe main.pl should be enough. And if the pp doesn't notice your main.pl uses subroutineX.pl then try pp -o main.exe main.pl subroutine*.pl Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response Hi Jenda, I learnt that zipping wont help me and i tried the way you specified, like: pp -o main.exe main.pl subroutine*.pl But even that did not help me. It creates a EXE file, but when i try using it all alone without the other supported files, it says that can't open subroutine.pl This is the problem i encounter. Thanks and Regards, Dharshana
checking hashref for value
Hi, I am trying to parse a xml file. Some of the tags are empty, like this one: # Data::Dumper output 'order_number' = {}, I have been trying to check if there is any content within the hashref (say for order_number) returned by XML::Simple but I am not getting the results I had hoped for. If I do this: if (defined($ref-{'order_number'}) $ref-{'order_number'} =~ /\w+/ ) { print found $ref-{'order_number'}\n; } I get found HASH(0xacacfe8). Using 'defined' gives me the same results. What is the correct way to check for content/values within a hashref? Is a element always defined if it is within the XML even if it has no values? Should I scalar it first? Thanx in advance, Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: checking hashref for value
On 12/4/06, Beginner [EMAIL PROTECTED] wrote: print found $ref-{'order_number'}\n; I get found HASH(0xacacfe8). That's a reference to a hash. It sounds as if you might want to ask the question Is that hash empty or not?, which the keys() function can answer: if (keys %{ $ref-{'order_number'} }) { print There's something in the order number hash.\n; } else { print Hash is empty.\n; } If you use keys() in a list context, you'll get a list of the keys of the hash. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: checking hashref for value
On 4 Dec 2006 at 8:47, Tom Phoenix wrote: On 12/4/06, Beginner [EMAIL PROTECTED] wrote: print found $ref-{'order_number'}\n; I get found HASH(0xacacfe8). That's a reference to a hash. It sounds as if you might want to ask the question Is that hash empty or not?, which the keys() function can answer: if (keys %{ $ref-{'order_number'} }) { print There's something in the order number hash.\n; } else { print Hash is empty.\n; } If you use keys() in a list context, you'll get a list of the keys of the hash. Hope this helps! Yes that worked fine. Thanx. Within the same xml file structure I also have 'address' = { 'line' = [ { 'line' = 'STARLING ROOFING' }, { 'line' = '338 EUSTON ROAD' }, { 'line' = 'DUBLIN' }, { 'line' = {} }, { 'line' = {} }, { 'line' = {} }, { 'line' = 'DB1 3BH' } ] }, Using that principle I thought I could do if (keys(%{$ref-{'address'}{line}[$j]-{line}}) ) { print Found , $ref-{'address'}{line}[$j]-{line}, \n; But I am getting an error: Can't use string (STARLING ROOFING) as a HASH ref while strict refs in use. Am I accessing the values incorrectly? Thanx Again. Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: goto return ?
On 12/3/06, Bill Jones [EMAIL PROTECTED] wrote: On 11/24/06, JupiterHost.Net [EMAIL PROTECTED] wrote: The trick is I can't seem to goto() return in do_some_stuff_and_return(), I'm sure since its so deep down... I guess I'm totally confused; I don't see how a goto can return back to the sub-rotine that called it: #! perl -w use strict; my $global = 99; main(); # The below goto returns here -- not back to the sub-routine. print Primary: Did I catch the new value $global?\n; exit; sub main() { print Main0: \$global is $global\n; goto the_goto if $global =~ /99/; # Goto does NOT return back here... $global = 60; print Main1: Did I catch the new value $global?\n; } sub the_goto() { print Goto0: \$global is $global\n; $global = 0; } __END__ The use of goto in this content is like using AUTOLOAD which causes the called routine to not return back to where it was called from but actually continue at the point AFTER the previous routine -- a little confusing to us beginners. This is the behavior of AUTOLOAD, which uses goto, but that's not quite how it works. 'goto sub' replaces the current routine. It's like exec() for subroutines. Consider the following: #!/usr/bin/perl use warnings; use strict; our $global = 99; my $lexical = 99; my $count = 0; mysub(25,75); $count++; the_goto(); print main0.0: global value is $global\n; print main0.0: lexical value is $lexical\n; sub mysub() { local $global = shift; my $lexical = $global; print mysub0.0: \$global is $global\n; print mysub0.0: \$lexical is $lexical\n; the_goto(); $count++; goto the_goto; $global = 60; print mysub0.1: Did I catch the new value $global?\n; } sub the_goto() { print goto$count.0: \$global is $global\n; print goto$count.0: \$lexical is $lexical\n; local $global = shift; my $lexical = $global; print goto$count.1: \$global is $global\n; #warning w/out goto print goto$count.1: \$lexical is $lexical\n; #warning w/out goto } __END__ Notice that we never pass the_goto() anything for @_. with goto, the_goto() completely replaces mysub(), inheriting its @_ (but not its local variables). This is different than simply calling it from within a subroutine or returning the caller early and then executing the goto. HTH, -- jay -- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom!
Re: Out of memory!, while extending scalar with vec()
From: kyle cronan [EMAIL PROTECTED] On 12/3/06, Bill Jones [EMAIL PROTECTED] wrote: On 12/3/06, kyle cronan [EMAIL PROTECTED] wrote: (1$ARGV[0]) Just a thought - The argument you are passing is really the two's complement; so you are really passing 256M (not 28) to the vec statement. So what you're saying is I should be using C! ;) Yeah, I'm implementing a lossy hash table and I want to create an array of 2^30 integers in my program, so this is correct. I was able to get it to work by using an array of 16 strings of length 2^26, then indexing into that array as well as into the vector there. But I'm still wondering why this would happen? After all, the machine has 16GB of ram. You should probably use PDL : http://pdl.perl.org/ http://www.perlmonks.org/?node_id=587436 Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Modules inter-relay ?
From: Mug [EMAIL PROTECTED] Say I have 2 modules ( below pseudo codes ) , which the first package ( InitGlobal ) will be used through out the other project modules. However, InitGlobal itself would relay on some other modules, which the modules using InitGlobal too. This sometimes caused some weir problem, or perhaps it just runable with luck. So I have to fix it one by on with to cutting some shareable code to another .pl file with require() to call them, but sound quite terrible enough. Not sure how do Perl handle this, or is that any standard way for module inter-relay ( or Is that any formal term to call this ? ) So you have two interdependend modules, right? A uses stuff from B, B uses stuff from A. You should reorder your code to prevent this. And if the two are too intertwined to do that, put them both into the same file. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: checking hashref for value
From: Beginner [EMAIL PROTECTED] Yes that worked fine. Thanx. Within the same xml file structure I also have 'address' = { 'line' = [ { 'line' = 'STARLING ROOFING' }, { 'line' = '338 EUSTON ROAD' }, { 'line' = 'DUBLIN' }, { 'line' = {} }, { 'line' = {} }, { 'line' = {} }, { 'line' = 'DB1 3BH' } ] }, Using that principle I thought I could do if (keys(%{$ref-{'address'}{line}[$j]-{line}}) ) { print Found , $ref-{'address'}{line}[$j]-{line}, \n; But I am getting an error: Can't use string (STARLING ROOFING) as a HASH ref while strict refs in use. Am I accessing the values incorrectly? Have a look at the XML::Simple's SuppressEmpty option. I think you'll have better luck with SuppressEmpty = '' or maybe SuppressEmpty = undef It's easier to test for undef than for an empty hash. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- 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 Query - Conversion of EXE file
You are making it harder for yourself than you have to. Don't ZIP anything ... pp -o main.exe main.pl should be enough. And if the pp doesn't notice your main.pl uses subroutineX.pl then try pp -o main.exe main.pl subroutine*.pl Jenda Hi Jenda, I learnt that zipping wont help me and i tried the way you specified, like: pp -o main.exe main.pl subroutine*.pl But even that did not help me. It creates a EXE file, but when i try using it all alone without the other supported files, it says that can't open subroutine.pl This is the problem i encounter. Thanks and Regards, Dharshana subroutine.pl? Anyway .. if you run the main.pl it works, right? If you run the created EXE in the same folder what does it do? If you run it from a different folder? If you run it on a different machine? What happens if you add BEGIN { print Starting the execution of main.pl\n } on the very top of main.pl? Do you get first this message and then the one about subroutine.pl? And if that subroutine.pl even in the same folder as the main.pl? Maybe you need to give pp the whole path to this subroutine.pl Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: checking hashref for value
Beginner wrote: On 4 Dec 2006 at 8:47, Tom Phoenix wrote: On 12/4/06, Beginner [EMAIL PROTECTED] wrote: print found $ref-{'order_number'}\n; I get found HASH(0xacacfe8). That's a reference to a hash. It sounds as if you might want to ask the question Is that hash empty or not?, which the keys() function can answer: if (keys %{ $ref-{'order_number'} }) { print There's something in the order number hash.\n; } else { print Hash is empty.\n; } If you use keys() in a list context, you'll get a list of the keys of the hash. Hope this helps! Yes that worked fine. Thanx. Within the same xml file structure I also have 'address' = { 'line' = [ { 'line' = 'STARLING ROOFING' }, { 'line' = '338 EUSTON ROAD' }, { 'line' = 'DUBLIN' }, { 'line' = {} }, { 'line' = {} }, { 'line' = {} }, { 'line' = 'DB1 3BH' } ] }, Using that principle I thought I could do if (keys(%{$ref-{'address'}{line}[$j]-{line}}) ) { print Found , $ref-{'address'}{line}[$j]-{line}, \n; But I am getting an error: Can't use string (STARLING ROOFING) as a HASH ref while strict refs in use. Am I accessing the values incorrectly? Hi Dermot You get some fun stuff to do don't you! To be honest I wouldn't go near XML::Simple because of exactly the problems you're experiencing. It turns XML into a nested hash structure where the hash values can be a hash reference, an array reference or a simple string scalar. To process the structure you have to check what sort of thing each value is so that you know what to do with it. The 'simple' seems to apply to the module itself, and the consequence is that the code which uses it has to be more complex. I would recommend XML::Twig or XML::TreeBuilder over XML::Simple which, while they may seem complex at first glance, will result more concise code. As for the problem in hand, I can't get XML::Simple to generate a structure like you've shown. My guess would have been dataset order_number address lineSTARLING ROOFING/line line338 EUSTON ROAD/line lineDUBLIN/line line/line line/line line/line lineDB1 3BH/line /address /order_number /dataset but that produces a hash element like this: 'line' = [ 'STARLING ROOFING', '338 EUSTON ROAD', 'DUBLIN', {}, {}, {}, 'DB1 3BH' ] and I couldn't find a set of module options to make it look like yours. Could you enlighten me please? To process your structure you need something like foreach my $line (@{$ref-{address}{line}}) { my $text = $line-{line}; print $text unless ref $text; print \n; } but this relies on prior knowledge that $ref-{address}{line} is an array reference and that the address line values are hash references if the line was blank. (Jenda's suggestion of using the SuppressEmpty option would help here.) Finally, here's the code to use XML::Twig print the text of the line elements of my XML above: my $tw = XML::Twig-new; $tw-parse($xml); foreach my $order ($tw-get_xpath('/dataset/order_number')) { foreach ($order-get_xpath('address/line')) { print $_-text, \n; } } which I think is hugely preferable. There are other ways to extract the information from the parsed data if you're not comfortable with XPath. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: checking hashref for value
From: Rob Dixon [EMAIL PROTECTED] Hi Dermot You get some fun stuff to do don't you! To be honest I wouldn't go near XML::Simple because of exactly the problems you're experiencing. It turns XML into a nested hash structure where the hash values can be a hash reference, an array reference or a simple string scalar. Ever heard of ForceArray, ForceContent and SuppressEmpty? If a tag may be repeated ... add it to ForceArray, if you have tags that sometimes do and sometimes don't have attributes use ForceContent. To process the structure you have to check what sort of thing each value is so that you know what to do with it. No, if you set the above options right you don't. The 'simple' seems to apply to the module itself, and the consequence is that the code which uses it has to be more complex. I would recommend XML::Twig or XML::TreeBuilder over XML::Simple which, while they may seem complex at first glance, will result more concise code. I'd love to see that. As for the problem in hand, I can't get XML::Simple to generate a structure like you've shown. My guess would have been dataset order_number address lineSTARLING ROOFING/line line338 EUSTON ROAD/line lineDUBLIN/line line/line line/line line/line lineDB1 3BH/line /address /order_number /dataset but that produces a hash element like this: 'line' = [ 'STARLING ROOFING', '338 EUSTON ROAD', 'DUBLIN', {}, {}, {}, 'DB1 3BH' ] and I couldn't find a set of module options to make it look like yours. Could you enlighten me please? Good catch. To process your structure you need something like foreach my $line (@{$ref-{address}{line}}) { my $text = $line-{line}; print $text unless ref $text; print \n; } but this relies on prior knowledge that $ref-{address}{line} is an array reference and that the address line values are hash references if the line was blank. (Jenda's suggestion of using the SuppressEmpty option would help here.) Finally, here's the code to use XML::Twig print the text of the line elements of my XML above: my $tw = XML::Twig-new; $tw-parse($xml); foreach my $order ($tw-get_xpath('/dataset/order_number')) { foreach ($order-get_xpath('address/line')) { print $_-text, \n; } } which I think is hugely preferable. There are other ways to extract the information from the parsed data if you're not comfortable with XPath. Using XML::Rules you could do something like: my $parser = XML::Rules-new( rules = [ line = sub {print $_[1]-{_content}.\n if $_[1]-{_content}; return}, ... ] ); If you instead wanted to have the whole address and use it somewhere later you could do something like: my $parser = XML::Rules-new( rules = [ line = sub { return '.lines' = $_[1]-{_content}.\n if $_[1]-{_content}; return; }, address = sub { chomp($_[1]-{lines}); $_[1]-{lines} =~ s/\n/\n\t/g; return 'address' = $_[1]-{lines} }, order_number = sub { print Received order number $_[1]-{id}\nFor client $_[1]- {clientname}\nAddress: $_[1]-{address}\n\n; }, ... ] ); Not sure this style looks very readable at first. You just specify what do you want to do with each tag and the stuff your handler returns is made available to the handler of the parent tag. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: goto return ?
Bill Jones wrote: On 11/24/06, JupiterHost.Net [EMAIL PROTECTED] wrote: The trick is I can't seem to goto() return in do_some_stuff_and_return(), I'm sure since its so deep down... I guess I'm totally confused; I don't see how a goto can return back to the sub-rotine that called it: perldoc -f goto caller() and Export has a similar fiddleness Look where its coming from: #!/usr/bin/perl use strict; use warnings; carp 'I am here'; foo(); sub foo { carp 'I am in foo'; # line 13, so far so good... } sub bar { baz('baz() called in bar()'); # line 17 *not* 22 where carp() was goto()ified (E.g. actaully called) } sub baz { local $Carp::CarpLevel = $Carp::CarpLevel + 1; goto Carp::carp; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: checking hashref for value
Jenda Krynicky wrote: From: Rob Dixon [EMAIL PROTECTED] Hi Dermot You get some fun stuff to do don't you! To be honest I wouldn't go near XML::Simple because of exactly the problems you're experiencing. It turns XML into a nested hash structure where the hash values can be a hash reference, an array reference or a simple string scalar. Ever heard of ForceArray, ForceContent and SuppressEmpty? If a tag may be repeated ... add it to ForceArray, if you have tags that sometimes do and sometimes don't have attributes use ForceContent. To process the structure you have to check what sort of thing each value is so that you know what to do with it. No, if you set the above options right you don't. Sure, if you set all those options you get all hash values being anonymous arrays (or text strings) and all array elements being anonymous hashes. But accessing all this gets ugly IMO. Using the XML sample in my previous post I have to write: my $ref = XMLin($xml, ForceArray = 1, ForceContent = 1, SuppressEmpty = '', ); my @address = @{$ref-{order_number}[0]{address}[0]{line}}; foreach (@address) { if (ref) { print $_-{content}; } print \n; } And you still need to check whether the content is a hash reference as there's also a problem with ForceContent and SuppressEmpty. If you enable both as above then empty content is stored as just a null string '' instead of { 'content' = '' }. Finally, because XML::Simple stores its data in hashes it can't preserve the document order of elements, and all those with the same tag must be grouped together. Consider: locations nameJenda/name countryCzechoslovakia/country nameRob/name townShrewsbury/town countryEngland/country postcodeSY1 1XB/postcode nameDermot/name postcodeW9 3RB/postcode /locations which isn't a nice use of XML I agree but I have had to work with worse. Parsing this with XML::Simple leaves us with { 'country' = [ { 'content' = 'Czechoslovakia' }, { 'content' = 'England' } ], 'name' = [ { 'content' = 'Jenda' }, { 'content' = 'Rob' }, { 'content' = 'Dermot' } ], 'town' = [ { 'content' = 'Shrewsbury' } ], 'postcode' = [ { 'content' = 'SY1 1XB' }, { 'content' = 'W9 3RB' } ] } which is of little use. All in all I prefer to avoid XML::Simple, but if it works for you then of course that's fine. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Matching long lists of patterns
Hello List, I've written a simple guestbook program and, of course, I get spammed like crazy. One of the ways I am trying to avoid this is to keep a list of keywords that, if they show up, cause the post to be rejected by calling a function called end. Currently, I am implementing it with code like this: sub process_post { my($new_name, $new_location, $new_website, $new_message) @_; end() if ( $new_website =~ / info\.aadityasood\.net| some\.bogus\.website| another\.bogus\.dummy /xi || $new_message =~ / health insurance|xanax|ringtones| viagra|cialis|student loans|casino| demadex|online poker|\[\/url\]| blackjack /xi ); # ... SQL insertion code here There's more to it, such as a list of bad IP addresses, but the example sufficiently expresses my point. I was just wondering, from a regular expression standpoint, if there is a more efficient way to implement this type of comparison. I was thinking perhaps putting all the keywords into various arrays such as @bad_websites and @bad_words, then looping through them, but I'm not sure if that will speed things up or slow things down. Thanks in advance, Adam -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Matching long lists of patterns
One of the subroutines for matching I used is shown as below. sub matching { my @[EMAIL PROTECTED]; my $eval=join ||, map { \$_[0]=~m/\$inits[$_]/io } 0 .. $#inits; my $ref=eval sub { $eval }; die can't eval: $@ if $@; return $ref; } my @init=qw/known keywords of bad users/; my $match_ref=matching(@init); my $key = ...; # the key you want to match if ($match_ref-($key) ) { action();# the action of yourself } When your matching list is long enough, using '/foo/ || /bar/' is pretty much faster than '/foo|bar/'. Hope this helps! -- Books below translated by me to Chinese. Practical mod_perl: http://home.earthlink.net/~pangj/mod_perl/ Squid the Definitive Guide: http://home.earthlink.net/~pangj/squid/ -- 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 Query - Conversion of EXE file
On 12/4/06, Jenda Krynicky [EMAIL PROTECTED] wrote: You are making it harder for yourself than you have to. Don't ZIP anything ... pp -o main.exe main.pl should be enough. And if the pp doesn't notice your main.pl uses subroutineX.pl then try pp -o main.exe main.pl subroutine*.pl Jenda Hi Jenda, I learnt that zipping wont help me and i tried the way you specified, like: pp -o main.exe main.pl subroutine*.pl But even that did not help me. It creates a EXE file, but when i try using it all alone without the other supported files, it says that can't open subroutine.pl This is the problem i encounter. Thanks and Regards, Dharshana subroutine.pl? Anyway .. if you run the main.pl it works, right? Yeah, mail.pl works If you run the created EXE in the same folder what does it do? The created EXE in the same folder works If you run it from a different folder? From a different folder it flags a msg Cannot open subroutine.pl which i have written in my main.pl like unless (open(LINE, subroutine.pl)) { die(Cannot open input file subroutine.pl\n); So, the die statement is executed. If you run it on a different machine? The same action as described above happens when run on a different machine What happens if you add BEGIN { print Starting the execution of main.pl\n } If the above statement is added, it prints the above statement and then prints the message as shown above, like: Starting the execution of main.pl Cannot open input file subroutine.pl on the very top of main.pl? Do you get first this message and then the one about subroutine.pl? And if that subroutine.pl even in the same folder as the main.pl? Maybe you need to give pp the whole path to this subroutine.pl But the requirement is that the resulting EXE should not have any depending files. So keeping subroutine.pl in the same folder does not satisfy the requirement. As, the resulkting file has to be distributed among ppl who does not have any knowledge on Perl. So, they can only run the exe file. And also, i wanted to know, if the EXE can be created in UNIX Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response Please guide me in the same. Thanks and Regards, Dharshana