Re: Problem using hidden variables
Kasturirangan Rangaswamy wrote: I have a perl program that has an include directive calling another Perl program in it. The structure is somewhat as follows first.pl -- #!/usr/local/bin/perl require second.pl $q = new CGI; print $q-hidden(-name='first', value='1'); second($q); End of first.pl second.pl -- #!/usr/local/bin/perl sub second{ use CGI; my ($q) = @_; my $first = $q-param('first'); print $q-hidden(-name='second', value=$first); // This does NOT WORK print $first; // This WORKS!!! } End of second.pl Your first.pl doesn't even compile. It prints this errors: Scalar found where operator expected at ./first.pl line 3, near $q (Missing semicolon on previous line?) syntax error at ./first.pl line 3, near $q Execution of ./first.pl aborted due to compilation errors. But when you add: use strict; use warnings; at the beginning, as you always should, it prints: Scalar found where operator expected at ./first.pl line 5, near $q (Missing semicolon on previous line?) syntax error at ./first.pl line 5, near $q Global symbol $q requires explicit package name at ./first.pl line 5. Global symbol $q requires explicit package name at ./first.pl line 6. Global symbol $q requires explicit package name at ./first.pl line 7. Bareword value not allowed while strict subs in use at ./first.pl line 6. Execution of ./first.pl aborted due to compilation errors. The second.pl prints these errors: Bareword found where operator expected at ./second.pl line 8, near // This (Missing operator before This?) Bareword found where operator expected at ./second.pl line 9, near // This (Missing operator before This?) Can't modify negation (-) in scalar assignment at ./second.pl line 8, near 'second', syntax error at ./second.pl line 8, near // This does syntax error at ./second.pl line 9, near // This WORKS Execution of ./second.pl aborted due to compilation errors. So, first of all, as always, start your programs with: #!/usr/local/bin/perl use strict; use warnings; unless you are completely sure you know what you are doing. Comments in Perl start with '#' and not '//' like in C++. Change it. Now, second.pl prints this error: Can't modify negation (-) in scalar assignment at ./second.pl line 8, near 'second', Execution of ./second.pl aborted due to compilation errors. This is because of -name='second' See the documentation of CGI.pm to know how you should use it: CREATING A HIDDEN FIELD print $query-hidden(-name='hidden_name', -default=['value1','value2'...]); -or- print $query-hidden('hidden_name','value1','value2'...); Fix it. Now, back to first.pl. As a first line it prints this: Scalar found where operator expected at ./first.pl line 5, near $q (Missing semicolon on previous line?) So, add the semicolon in the previous line... Now, it prints: Global symbol $q requires explicit package name at ./first.pl line 5. So declare your $q as a lexical variable with my, or a package variable with our, or use a full name like $somepackage::q. When you fix this, you get this error after running first.pl: second.pl did not return a true value at ./first.pl line 4. Read perldoc perlmod and perldoc perlmodlib. Read about require: perldoc -f require The file must return true as the last statement to indicate suc- cessful execution of any initialization code, so it's customary to end such a file with 1; unless you're sure it'll return true otherwise. But it's better just to put the 1;, in case you add more statements. So, add 1; at the end of second.pl... Now, it prints: Use of uninitialized value in print at second.pl line 9. input type=hidden name=first value=1 /input type=hidden name=second value= / This is because the second CGI parameter is undefined. We can never be sure about the user input, so we have to use some default value in case there is no second parameter passed to the script, either with CGI by the browser or with second=something command-line argument, so instead of this: my $first = $q-param('first'); there should be: my $first = $q-param('first') || 'default value'; Now it works, but is insecure. There is a cross-site scripting vulnerability. You should change: print $first; to: print $q-escapeHTML($first); to escape the HTML markup in $first. There was quite a lot of problems with those two simple pieces of code you have posted, so I suspect that there are much more in your full programs. If you want more help with them, please contact me privately off-list, I might see what I can do. -- ZSDC Perl and Systems Security Consulting -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
PERL IDE
Hello I am new to perl , is there any good IDE to develop simple perl forms with firebird database which is a no brainer. Please advice Mohammed -- 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 IDE
On 05 Mar 2004, at 20:36, Alexander Douglas wrote: Hello I am new to perl , is there any good IDE to develop simple perl forms with firebird database which is a no brainer. Please advice Mohammed Which OS ? For Linux and Mac OS X.. None that I can think of.. Perhaps some commercial ones but I've not tried commercial IDEs. Windows I don't have a clue, I don't waste my time on that. If anyone knows of one for Linux or Mac OS X I'd like to know as well. Of course, there are some people that will answer vim and xemacs or even BBEDIT but they are confused and worse than that they have not read your question correctly. Cheers, Jerry -- 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 IDE
I don't know about firebird database but a really good text editor for web and perl development for Mac is BBEdit offered by http://www.barebones.com The MacPerl integration with syntax check is awesome. Alo has incredible grep functionality. OptiPerl IDE is good for Windows again I don't know about firebird database. --Teresa At 09:41 AM 3/6/2004, you wrote: On 05 Mar 2004, at 20:36, Alexander Douglas wrote: Hello I am new to perl , is there any good IDE to develop simple perl forms with firebird database which is a no brainer. Please advice Mohammed Which OS ? For Linux and Mac OS X.. None that I can think of.. Perhaps some commercial ones but I've not tried commercial IDEs. Windows I don't have a clue, I don't waste my time on that. If anyone knows of one for Linux or Mac OS X I'd like to know as well. Of course, there are some people that will answer vim and xemacs or even BBEDIT but they are confused and worse than that they have not read your question correctly. Cheers, Jerry -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Comparing text text::diff
I asked a question a couple of days back on perl beginners at Yahoo groups as well on other forums. to compare two text files/strings and to print the results if both are different and was advised to use Text::Diff. Actually, I am working on project of transcription, where typist types the $text1 and save it. Then the QA (Quality Control) person logs in and make appropriate corrections to file and save it again as $text2. Now I have to compare $text1 with $text2 for the feedback of typist, so that he can view the changes QA made to the file and should not repeat the same in the next files. So far so good, I used the Text::Diff and it solved my problem, when I tested it for small text containing 3 - 4 lines paragraph. Now the problem arises again. I tested it for 3-4 lines paragraph, but when script went live, the text strings were quite big like some contained 20 lines in a single paragraph. Text::Diff matches until \n || \r is inserted. Okay, the module is doing it's job well I have no problems with it. Now the problem is if only QA changes 'is' to 'was' or removes any white space character in 20 lines. Text::Diff prints the whole 20 lines because the changes were made. So sometime typist reads whole 20 lines and found nothing in it except for removal of white space which obviously he is unable to see or sometime only 'is' to 'was' change (if the file contains no other big mistakes). So instead of helping the typist to review the feedback from QA, it becomes a time waster. Now, I am looking for a way where I can highlight (by enclosing changes with B/Btags) the changes (if the $text2 is different from $text1) either within the output of Text::Diff or separately from it. TIA, Sara. - #!/usr/bin/perl use Text::Diff; use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI; my $q = new CGI; my $text1 = $q-param('text1') || 'this is text line and it contains the ___ line'; my $text2 = $q-param('text2') || 'this is text line and it contains no blank line'; print $q-header(); my @output; my $diff = diff \$text1, \$text2, { STYLE = Context, OUTPUT = [EMAIL PROTECTED], CONTEXT = 0, }; print @output;
Re: PERL IDE
I use jEdit www.jedit.org (based on java) in Linux Mandrake 9.0 and Win2K. I have used Vim, Crimsom Editor, optiPerl... but until the moment the best one for my jEdit, it works equal in any operating system. Alex. - Original Message - From: Alexander Douglas [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, March 05, 2004 2:36 PM Subject: PERL IDE Hello I am new to perl , is there any good IDE to develop simple perl forms with firebird database which is a no brainer. Please advice Mohammed -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
About HASH crypt
Hi,all I use samba and LDAP to build a PDC, but samba build NT Password via hash4, and have a program mkntpwd to generate crypted password, does perl has any module or function to do this? -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing array as First argument
R. Joseph Newton wrote: Hi Malik, If you pass a reference to the array as the first argument as below you can keep the array separate from the other arguments you are passing. @abc = qw(1 2 3); $x = 4; $y = 5; testsub([EMAIL PROTECTED], $x, $y); sub testsub($$$) { ($abc, $x, $y) = @_; print Array @$abc\n; print x $x\n; print y $y\n; } Thank you for using the clear scalar syntax in your prototype. Joseph Yes, but now you explicitly pass an array reference. As you have said, this is better for readability. If this is just any darn subroutine that you are using yourself, you shoud do it this way (Actually, then I wouldn't prototype at all). But, if this is being exported, what is the harm of sub testsub ([EMAIL PROTECTED])? If a beginner can understand the concept of prototyping and referencing, I think they can gather an array reference is being passed. When you program for an end-user programmer, you should use [EMAIL PROTECTED] if you prototype something like this. -will (the above message is double rot13 encoded for security reasons) Most Useful Perl Modules -strict -warnings -Devel::DProf -Benchmark -B::Deparse -Data::Dumper -Clone (a Godsend) -Perl::Tidy -Beautifier -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: HERE DOCUMENTS
WC -Sx- Jones wrote: This is Part One of a Multipart posting - just to see if we can't keep things in the list archieves (Give the listbots something to do :) (These are not really posted questions so much as they are things that beginners need to consider.) HERE DOCUMENTS * Here documents are used to embed lines of text in a Perl script, for printing or variable assignment. $foo = EOT testing one two three $four EOT print _Html_; various basic html can go here sprinkled with Perl variables... _Html_ NOTE that the ending portion of a heredoc must be in column zero -- I have noticed that having indented can cause issues at times... * Variable interpolation is on by default. You turn it off by making it single quoted. print 'EOP0' interpolation is off: $foo $bar are not converted to data EOP0 Whether you use Double quotes, the variables are interpolated into their corrisponding data: print EOP1 interpolation supported: $foo is related to $bar EOP1 # The following is somewhat dangerous; use with # appropriate caution - * Commands will be executed if the ending-string uses backticks. $sommand_results = `END_OF_COMMANDS` ls -al ps -aux END_OF_COMMANDS Also, I previously posted how to cram single lines of text into an array; it is left upto the reader as an exercise to find that posting out there in Usenet land. That's a small start to what I hope will become a long term thing :) So, if you have a statement or neat easy to understand fact about HERE Documents, post it; keep this Perl Chain Posting going... If you want to indent your ending line (EOF, EOT, END_OF_COMMANDS, etc.) for readability, you can do so like this: print EOF; # Single quotes turn off variable interpolation (found out hard way) This is some text. More text. foo = $foo EOF -- Andrew Gaffney Network Administrator Skyline Aeronautics, LLC. 636-357-1548 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: links in POD
You know, this is all sort of like using DocSet 0.16 from CPAN http://search.cpan.org/~stas/DocSet-0.16/ Have you seen it? Not until you just mentioned it. Looks interesting - thanks for the suggestion! Bob -- 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 filenames? [:: ?Kinda Solved? ::]
WC -Sx- Jones wrote: Hmmm, I get 3 Indians in only the first variable anyways =/ Doesn't surprise me. The x is a concatentation multiplierfor strings. Why not just say what you want: $_ = 'Litttle' for my ($onelittle, $twolittle, $threelittle, ) ; print 1 $onelittle 2 $twolittle 3 $threelittle Euro-American Doughblobs\n\n; One thing notable about all of this is that no work is saved, or very little. Hmmm... my $number_names = [qw /Zero One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Noneteen / ]; # Yeah, we only need 1..3, but I only want to write that once per language. print $number_names-[$_] little for (1..3); print Euro-American Doughblobs\n\n; Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Reading File grep according item 5 and sorting
Bjorn Van Blanckenberg wrote: On 3-mrt-04, at 09:56, R. Joseph Newton wrote: I understand how the code works It reads the file end split every line according to the tabs and then sorts everything. For returning the info it looks at colomn 5 (1-based indexing) and if colomn 5 of the next line is the different print an extra newline. So it basically does what I want if colomn 5 is exact the same not if it start with string from colomn 5. So It is basically what I need but without reordering (sorting) and looking at every line that starts with colomn 5 and then sorts that blok of tekst. I hope I explaned it well enough. Thanks Well, that is good, but it leaves you having to do a lot of work over again, mostly because you handled things in a limp early on. That bit of code early on: my @sorted = map { $_-[0] } sort { $a-[5] cmp $b-[5] } map { [ $_ , (split /\s+/) ] } @fields; does a sort, then re-concatenates the lines as sorted. Then they have to be picked apart again in order to look for places to insert a newline. What you want to do will require design, not imitation. First, think about the requirements per line: While the fifth token in the line is the same [which none are, since they all have different decimals slopped onto the end], you wish to collect them in a group. Then you want to print out the items in the group line by line. If you want groups of lines, why are you throwing them together into a garbage bag of an array? my %fifth_item_groups; while (my $line = INFILE) { chomp $line; next unless $line; my @tokens = split /\s+/, $line; my $fifth_item = $tokens[4]; $fifth_item =~ s/\d+$//; $fifth_item_groups{$fifth_item} = [] unless $fifth_item_groups{$fifth_item}; push @{$fifth_item_groups{$fifth_item}}, [EMAIL PROTECTED]; } foreach my $grouping_key (sort {$a cmp $b} keys %fifth_item_groups) { print join(\t, @{$_}), \n foreach @{$fifth_item_groups{$grouping_key}}; print \n; } The code above should perform the task specified--with no subsort. That work is for you to do. Hint: I chse my data structures pretty carefully, so that you should not have much trouble accessing any element by which you might wish to do a subsort. When you have made use of this and added the subsort, please post again and show us what you come up with. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Passing array as First argument
William Gunther wrote: If a beginner can understand the concept of prototyping and referencing, I think they can gather an array reference is being passed. Actually no. I have not seen this in the last year of reading this list. The vast majority of newbie traffic that i have seen among the 22K+ posts inmy archives provides strong indicatins of resistance to understanding references. Syntactic tricks that allow beginners to offer aguments without explicit referencing only fuzz up the matter. At a later stage in development, perhaps, the prototyped form with the reference to type indicator may be helpful, because it provides added information about the function--when looking at the prototype. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Why don't it print ?
Hi all, why don this littly thingy work? It should print, sleep and after sleep print again but it does print both at same time. Not one before sleep and one after. I tried: while ($i 10) { print'sleep...'; sleep(10); print done\n; } Anyone can help me with that? Thx! :)
Re: Why don't it print ?
On Sun, Mar 07, 2004 at 05:57:57AM +0100, [EMAIL PROTECTED] wrote: Hi all, why don this littly thingy work? It should print, sleep and after sleep print again but it does print both at same time. Not one before sleep and one after. I tried: while ($i 10) { print'sleep...'; sleep(10); print done\n; } Anyone can help me with that? Thx! :) Buffering. Add $| = 1; near the start of the program. perldoc perlvar -- 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