Writing a column after column
Hi all, I need to consolidate columns of data available across different directories into a single excel csv file. Usually we write to a file row after row but for the current task I have, it would be convenient to write the file column after column. Is there a file writing mode for this? If not, I guess, I will have to write the matrix row by row and then take a transpose. Let me know what you guys think and if you could share some skeleton of code for something like this would be great. Thanks. -vijay -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: http headers
Hi There, Here is another one I always use : sub parse_form { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $head = $ENV{QUERY_STRING}; } @pairs = split(/\?/, $head); # split vars using ? as delimitor foreach $pair(@pairs) { ($name, $value) = split(/=/, $pair); # split var and value using = as delim. $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; ${$name} = $value; } } # End sub parse_form Good luck ! David > > Most recent editions of Perl come with the CGI module, > which is what you want. Type "perldoc CGI" at your > friendly neighborhood command prompt. The O'Reilly > book "CGI Programming with Perl" has a good overview, > as do no doubt countless other books. > > The basic steps are: > > use CGI; > my $cgi = new CGI; # Optional O-O interface > print $cgi->header, $cgi->start_html("My Page"); > print $cgi->param("foo"); # print value of "foo" > param > print $cgi->end_html; > > Note that you can also use it to output the HTML > response, although you don't have to. More details in > documentation. > > - John > > --- Conan Chai <[EMAIL PROTECTED]> wrote: > > hi, > > > > are there any perl modules that splits the http > > request headers into name/value pairs? > > > > Conan > > It Will Come To Us !!! > > [EMAIL PROTECTED] > > > > > __ > Do You Yahoo!? > Yahoo! Games - play chess, backgammon, pool and more > http://games.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: Unix to dos; dos to unix...
Hi There, Just a small addition on the remarks : I don't know if you realy want this to automate, but "vi" can do it as well. Just type : :1,$s/[Ctrl + v] [Ctrl + m]//g The [Ctrl + v] makes you able to type in an escape character. Most of all the [Ctrl + m] (^M) is bothering you. :) I know, I know. It's beginners@perl and not beginners@unix. Just want to help. Good Luck !! Regs David - > > There is a utility out there that will convert unix-style end-of-lines (LF) > to dos-style (CR/LF)... > > Just for giggles, I'm trying to write a perl script to do this... > > Here's what I've tried... > > while () { > $line = $_; > $line=~tr/\012/\015\012/; > print OUTFILE ("$line\n"); > } > > The problem is that the output, when viewed with notepad, contains > inappropriate line breaks... > > The same input file, when converted using the unix utility unix2dos, > converts "properly." This leads me to believe that I'm missing something > obvious here > > I'm not asking for the answer per se, but perhaps a pointer? > > -- > Ron Powell > Senior IT Analyst & > Network Administrator > gomembers, Inc. (Baltimore Office) > [EMAIL PROTECTED] > 410-494-1600 x4058 > <<...OLE_Obj...>> > > > > - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: select from oracle and write to file
Hi Garrett, Not shure if this is where you are looking for, but here is some simple info on how to write data to a file. If it is not sufficient you'll have to wait for the real ones to wake up :) $file = "/path/to/file"; open(F, "> $file"); print F "What you want to store in your file, can also be a $variable"; close(F); ## ">" says create new or overwrite, ">>" says append or create new. Good Luck !! Regs David -- > > Hello all, > > Solaris, Oracle 8.1.6, Perl 5 > > How do I write my selected row from Oracle out to a new file? Below is what > I have so far. I can select the row, but I don't know how to write it to a > new file: > > > #!/usr/local/bin/perl -w > # > # REMEMBER! Set the environment variable: ORACLE_HOME=/path-to-oracle BEFORE > running this script. > # > > use strict; > use DBI; > > my $dbh = DBI->connect( 'dbi:Oracle:db', > 'user', > 'passwd', > { > RaiseError => 1, > AutoCommit => 0 > } > ) || die "Database connection not made: > $DBI::errstr"; > my $sql = qq{ SELECT oid FROM bv_ep_project }; > my $sth = $dbh->prepare ( $sql ); > $sth->execute(); > $sth->finish(); > $dbh->disconnect(); > > Thank you for your help!!! > > -garrett > > _ > Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. > > > -- > 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]
How to fill and use Hashes
Hi There, I have never used hashes before, althought they seem to be interesting I didn't know the exact use for it. But as times are changing I think I just came to a point where I need a hash, but how do I create one and how do I use it ? Can anyone assist ? this is what I want to accomplish : foreach(HASH) { if (($pdf1) && ($link1)) { exec("ln -s ${link1} ${base}/${pdf1}"); } # End if } # End foreach So I have 2 variables that always come together. To write an if then statement for 10 times because I have 10 * pdf and link variables looks bad to me. So I am looking for the foreach HASH something. I know it must be possible. Who can assist ? Plus, how do I fill a HASH ?? : " HASH = ($pdf1, $link1); "?? How to proceed with my next " HASH[1] = ($pdf2, $link2); " ?? Thanks for your help in advance !!! Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Editing Root File
Hi Hengky, I assume you work on a Unix server (root). Create a shell-script might be one of the solutions : -r-sr-x--- 1 root apache 24576 Aug 6 1998 /dns.sh You can put in here the exact command you want to run as root. Make sure the file is owned by root and the group is the same as your webbrowser is running as. Make sure that you don't have the worldwide permissions set. I never can remember the digits for the sticky bit, but : chmod 550 /dns.sh; chmod u+s /dns.sh should work as well. I don't know if there is a real way in perl to solve this, will leave this to the perl guru's. Regs David -- > > > i'd like to create updating dns and user and password under web. > but i don't have suid so i cannot change the file or running binary file > that use root permision... > > can somebody help me with this...? > > does anybody have a sample program that can run or edit root file...? > > pls... > > > Thx. > > Hengky > == > Knowledge is belong to the world > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Graphics Library
Hi Arran, I know there is one called GD : http://search.cpan.org/doc/LDS/GD-1.38/GD.pm Unfortunetly I have never used it yet, but I am sure someone has. It's just that they are not awake yet, the guru's awake at aprox 16:00 CET :) That's why I start late :) Good luck! Regs David -- > > Does perl have an graphics library where you could create your own graphics? > > and how would i go by using it? > > > From: Arran > For more contact details goto: > Http://www.arran4.8m.com/ > /This document is provided in HTML as well as text/ > > If builders built buildings the way programmers wrote programs, then the > first woodpecker to come along would destroy civilization. > > We are the out casts of society, but when they relise its the out casts that > create society, we will fall. > > Everything I know about thermal expansion I learnt from Neon Genesis > Evangelion! > > > > -- > 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]
How to get number of characters from var?
Hi, I have a question about determine how many charactars contain a var. Does anyone know, there will probably be a simple command, but I can't find it. Assuming $_ = /hello/this/will/have/to/be/IMPORTANT/ONLY/AND/CAN/BE/LONG/features.txt $dir = substr("$_", 0, -13); ## Remove features.txt $link = substr("$dir", 27); ## Remove the not used and already defined $base @href = split(/\//, $link); ## put this in an array $lineteller = ( scalar(@href) -1 ); ## To determine the last word $href = "$href[${lineteller}]"; ## and make $href this last one $nhref = ???($href);?? Determine number of characters $header = substr("$link", 0, -${nhref}); ## Use it to def $header without $href So what I need out of $_ : $dir = "/hello/this/will/have/to/be/IMPORTANT/ONLY/AND/CAN/BE/LONG"; $link = "/IMPORTANT/ONLY/AND/CAN/BE/LONG"; $href = "LONG"; $header = "/IMPORTANT/ONLY/AND/CAN/BE/"; I know there is a faster way to get the last value of an aray, but I don't know exactly how anymore (help is welcome). The most important now is, how do I get the number of charactars out of $href ?? Thanks for your help in adance !! Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Pattern matching
Hi Francesco, You could do it like this : $line = "qw001234po001234 ghjkldzx001234 tgbnhy"; ($pw0,$uid1,$pw1,$uid2,$pw2) = split(/\s+/, $line); print NEWFILE "$uid1 $pw1 \n"; print NEWFILE "$uid2 $pw2 \n"; Your current file does have to contain 5 fields. Hope this is what you are looking for. Regs David > > I have many files with username and passwd.The old files are in format: > > qw001234 asdfgh# all usernames are composed by qw/po/zx + 00 + 4 > number > > The new files have three usernames and passwd for each number on each > line: > > qw009876 qwertypo009876 poiuyt zx009876 mnbvcx > > To patch the old files someone before me made a new file with the other > "po" and "zx" but with a big error.The format is > > qw001234po001234 ghjkldzx001234 tgbnhy > > There's not the passwd for the user in the old file(ever qw).Now I need > just one file with in the format > > qw001234 qwerty > qw009876 qwerty > po001234 ghjkld > po009876 poiuyt > zx009876 mnbvcx > zx001234 tgbnhy > > > Please help me.Thanks. > > > > > -- > 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: Split
Hi Fransesco, Let's try this one then :) ($username, $name) = split(/:/, $line); chomp($username); chomp($name); I think you just learned chomp :) Regs David - > > I haven't yet resolved my problem with pattern matching and I'm in front > of another problem. > I have a file with > > username: name#there are one or more white space > > I need to make a new file with > > name username > > I think I can do it with split but I don't know how.A little help?Thanks > > > -- > 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: perl-Tk static
Hi Drieux, Hhhm, Unix rules, but we still need men : make babies Make: Don't know how to make babies. Stop. Hope he didn't mess up someone elses "test" too much :) Regs David --- > > > On Wednesday, May 15, 2002, at 04:34 , Alan Drew wrote: > [..] > > > > For static linking the following is how it is supposed to work > > (I think, but I don't use static linking normally, this scheme > > worked as far as this on one trial under SunOS4.) > > > > perl Makefile.PL > > make > > make tkperl > > make test # should work > [..] > > > > The first two steps are fine. Problem is, when I come the next step: > > > > [ot@papc-mag-17 Tk800.023]# make tkperl > > make: *** No rule to make target `tkperl'. Stop. > > > > Any ideas? Thanks in advance. > > oh dear - you are chasing a phantom. > > http://www.lns.cornell.edu/~pvhp/ptk/qna2.html > > { although a reasonably old one by computer times } > > the problem is that there is no target 'tkperl' in > the make file - hence it will not make the target... > > xanana: 76:] make happy > make: *** No rule to make target `happy'. Stop. > xanana: 77:] > > no wonder I am SAD. > > so the question is what happens when you do the make test side... > > ciao > drieux > > --- > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: HTML tables?
Hi Barry, I have been looking for you, but the only options I could find in "Perl in a Nutshell" is the following : Form Generation start_html Generates an tag. end_htmlGenerates an tag. autoEscape Sets whether to use automatic escaping. isindex Generates an tag. startform Generates a tag. start_multipart_formGenerates a tag for multipart/ form-data encoding. textfield Generates an tag. textareaGenerates an tag. password_field Generates an tag. filefield Generates an tag. popup_menu Generates a popup menu via and tags. scrolling_list Generates a scrolling list via and tags. checkbox_group Generates a group of checkboxes via multiple tags. checkboxGenerates a single checkbox via a tag. radio_group Generates a group of radio buttons via tags. submit Generates a tag. reset Generates a tag. defaultsGenerates a tag. hidden Generates an tag. image_buttonGenerates a clickable image button via a tag. button Generates a JavaScript button. Regs David -- > > Does anybody know of a module to manage generating HTML tables? Is > there anything in CGI.pm? Does anyone have any tips to generating > semi-complex tables? > > Barry Jones > DATABUILT, Inc. The Global AEC Information Company > 1476 Fording Island Rd. Bluffton, SC 29910 > (843) 836-2166 office > > "Life is like a dogsled team; > if you ain't the lead dog, the scenery never changes." > - Lewis Grizzard > > > -- > 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: Perl script idea
Hi Jonathan, I am not writing the script for you but at least some code I used to something similar. --- $entry = `ypmatch $userid passwd 2>/dev/null`; @entry = split /:/, $entry; $encrypted = "$entry[1]"; $pwuser = "$entry[0]"; chomp($pwuser); chomp($userid); if (!($userid)) { open(FH, "< $userfile"); while() { ($userid, $password, $group) = split(/:/, $_); if (!("$pwuser" eq "$userid" )) {shift;} } } if (crypt($password, $encrypted) ne $encrypted) { #Do something } mkdir $newic, 0750 || die "Problem creating directory $directory: $!\n"; - open(FH, ">$base/.htacces"); print FH me; print FH and; print FH someonelse; close FH; With 4 and 5 I can only wish you good luck !! Regs David - > > I am wanting to write a script to handle a few things > 1. decrypt an encrypted password > 2. create new directory > 3. put .htaccess file into the new directory > 4. allow file upload and subsequent unzip of files into the new directory > 5. email to admin of the creation and subsequent events > > The password I want to use is a power-user pw (almost root priviledges) so I > want to have the thing entered into the form in an encrypted version, and > the script would call another script (not a sub) to handle the decryption > and pass back the argument to the system call to login as the user and > create the directory. > ie: enter user: bear > enter pw: r4t4 > dir to create: fred > file to upload: freddies_pics.zip > user for logins: friends > pass for logins: guest > > script does: > system login: bear > password: yada > > login successful > mkdir fred > cd fred > upload successful > unzip freddies_pics.zip > touch .htaccess > encrypt guest > put friends:erisy > .htaccess > cat ../.root.priviledges > .htaccess > output to screen: > Directory created successfully > http://server/fred/ > please login to verify > > mail to admin: > subject: New directory and files done for $user > system login: bear > password: yada > > login successful > mkdir fred > cd fred > upload successful > unzip freddies_pics.zip > touch .htaccess > encrypt guest > put friends:erisy > .htaccess > system is locked down to them and the other codes per settings. > > That's the design of the flow, now I just need to get the stuff written. > Any suggestions on an easy way to do this? > > Thanks, > Robert > > -- > 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]
How to use crypt ??
Hi, Right now I am a little lost. Trying to use crypt() to encrypt a given password. I know how to compare a given password with an encrypted one, but to encrypt one myself and save it, doesn't work for me for some reason. You would say, Ah of course forgotten to give your encryption key. That's right which one uses apache/Unix/etc ?? So what it is all about probably is this : my $crpw = crypt("$pw", "What key "); Hope for your help ! Regs David For giving you the overview, here is my program : #!/usr/bin/perl use CGI qw(:standard); use strict; print header, start_html(-Title =>"Create external user", -BGCOLOR=>"#99"), h1('Create external user'), start_form, table, Tr(td("Please enter userid"), td(textfield('userid') )),p, Tr(td("Please enter password"), td(password_field('pw') )),p, Tr(td("Please select group"), td(popup_menu('group', [ qw(iclab Philips All) ]) )),p, Tr(td(submit(-Value =>"Create"))); print ""; print end_form; if (param('pw')) { my $pw = param('pw'); my $userid = param('userid'); my $group = param('group'); my $crpw = crypt($pw); my $pwline = "${userid}:${crpw}"; print $pwline; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - End Forwarded Message - -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: command-line commands within a Perl script
Hi, A possible way : #--- use File::Find; use File::stat; my $directory = "/user/IPlib/IPlib/"; find(\&search, $directory); } sub search() { my $file = $File::Find::name || shift; if ( -d $file ) { push @dirs,$file; } else { push @files,$file; } print @files; print @dirs; } Regs David > Hi, > > I have a directory with several subdirectories, each full of several dozen > Word files. For each subdirectory, I need to run the checksum app against > all of that directory's files and output a file into that directory with the > checksum results. How can I do this? I'm very unfamilar with running > command-line commands from within an Perl script. I know to change > directories, you can do something like this: > > $changeDir = "cd ".$startingDir; > system($changeDir); > > but what about retrieving the list of subdirectories from the starting > directory? How can I do this? > Thanks for your help. > > > -Jose > > > -- > 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]
Remove 1 or more whitespaces at the end of $_
Hi, I know how to delete 1 or more whitespaces at in a line using : while { s/\s+//g; } close IN; #- But How do I specific delete 1 or more whitespaces at the end of the line ? using : while { s/$\s+//g; } close IN; Didn't work. Does anyone have the solution for me ?? Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: AW: Remove 1 or more whitespaces at the end of $_
Thanks it works !! I also got a private e-mail that said : s/\s+$//; And that also works ! Regs David -- > > Hi David. > > if you have an variable like this > > $mystring = "hello this is a string "; > $chop($mystring); > > the chop command is what you are looking for I think. > Just try it out. > > Heiko > > >>-Ursprüngliche Nachricht- > >>Von: David vd Geer Inhuur tbv IPlib > >>[mailto:[EMAIL PROTECTED]] > >>Gesendet: Montag, 27. Mai 2002 14:49 > >>An: [EMAIL PROTECTED] > >>Betreff: Remove 1 or more whitespaces at the end of $_ > >> > >> > >> > >>Hi, > >> > >>I know how to delete 1 or more whitespaces at in a line using : > >> > >>while { > >> s/\s+//g; > >>} > >>close IN; > >> > >>#- > >> > >>But How do I specific delete 1 or more whitespaces at the end of > >>the line ? > >>using : > >> > >>while { > >> s/$\s+//g; > >>} > >>close IN; > >> > >>Didn't work. Does anyone have the solution for me ?? > >> > >>Regs David > >> > >>-- > >>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: reference to an array
Hi Willy, What does push and what is $_ That will probably be your question. Here is one example : open(FH, "< $file"); while { ## is the File Handler we just openened with open ## We do something with ?? ## Yes, no var is set but instead we use $_ for the current line. ## Now we can set a condition, and if $_ matches the requirement ## I want to store this line into a seperated array : if(m/mymatch/g) { ## You don't have to specify the $_ anymore as this is default (I heard). ## Now we have the line that matches our key and I want to store it together ## with all the other lines in the document that contain this searchstring ## So : push @mymatches, $_ ; ## Or of course: push(@mymatches, $_); ## We just pushed the current line (of the while ) into the end of our ## array @mymatches } ## And of course we close our if-statement } ## And we close our while statement Hope this explaines your questions. Regs David -- > > drieux <[EMAIL PROTECTED]> has kindly answered > my question about $/ to change the way a loop parses text > but his answer uses stuff which i am not familiar with yet: > > drieux wrote... > > b) you might want to pass in a reference to the array - and fill it up > > push( @$array_ref, $_ ) > > > > > > i almost understand this- not really though... > > i'm curious for an explanation :) (btw- thanks drieux) > > > > willy > > *yawn* i need a nap... > > > > > -- > 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: checking for an empty string
while () { if (!($_)) { if(m/^email address/) { } } } I think you want to be shure that you have input, so you match only if the current line is not empty. Regs David -- > > Hi guys, > > while($line = ) > { > if ($line =~ /^email address/) > { > } > } > > How can I check if $line contains a value or is empty? > > Thanks a lot! > > __ > Do You Yahoo!? > Yahoo! - Official partner of 2002 FIFA World Cup > http://fifaworldcup.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]
skip first array entry and exit foreach loop only
Hi, I am looking for a nice solution for the following problem : I have a directory stored in $header. I need to seek each directory for a specific file, but I have to start in the deepest dir and than go upwards. Using the split @header first value is always empty as it is splitting on " */*". As /user does not contain any data in front of the / I have a "problem". Of course I can do the "if (!($head)) { next; } ", but I hope there is a more beautifull solution. Any ideas ?? Also ones I found the file I need to find, I would like to exit out of the foreach loop only. How do I do ?? The example is below. Thanks for your help in advance !! Regs David # $header = "/someone/I/know"; sub pre { @header = split(/\//, $header); chomp @header; $dm = "/user/IPlib"; foreach $head(@header) { #if (!($head)) { next; } ?? $dm = "$dm" . "/$head"; push @dv, $dm; @rdv = reverse(@dv); } # End foreach foreach $rdv(@rdv) { if ( -f "${rdv}/feature.tmpl" ) { open (FH "< ${rdv}/feature.tmpl"); @template = ; close FH; ## ?? Exit out of this foreach loop only ?? } # End-if else { next; } } # End sub pre -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: skip first array entry and exit foreach loop only
Hi, This is indeed much faster, just substitute the last directory off of the path when you're done checking with the current. Looks better indeed !! Nikola, using File::find searches all the files and as the directory's can hold many files and directory's I prefer to just do the test on 1 file. But I know File::Find and it is very usefull !! Thanks for your help ! I understand the command "last" just tells the foreach loop to quit when done. Looks realy good !! Thanks !! David --- > > > > > > > > Hi, > > > > I am looking for a nice solution for the following problem : > > > > I have a directory stored in $header. I need to seek each > > directory for a specific > > file, but I have to start in the deepest dir and than go > > upwards. > > All that splitting and reversing seems complicated. Why not > just a simple loop that snips off the last part of the path > each time around? Something like this: > > #!/usr/bin/perl > > use strict; > > my $path = '/usr/local/bin'; > my $file = 'foo'; > > while ($path) { > print "Checking $path\n"; > print("Found $path/$file!\n"), last if -e "$path/$file"; > $path =~ s!/[^/]*\z!!; > } > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Hi, I am struggling with something very stupid. I know the print syntax, but I would like to use the "print <
Re: Spaces...
Hi Paul, Just use : ($month, $day, $time) = (split /\s+/, $line); the /s+ stands for 1 or more spaces. Regs David - > > I have a logfile that has the following format: > > month day time > > The problem is splitting on the "space" - split(/ /). Sometimes there are more than >one space. How can I get perl to split on 1 or more spaces? > > > -- > 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]
How to communicate with local ports
Hi, My collegue is looking for a solution (Cpan module) to be able to communicate on a low level with for example a printer-port. He has designed a specific type of hardware, and needs to send signals to that port. Currently he is using C to do the work, but wants to rewrite it in Perl. Any advise on modules to talk low-level to a lpt/paralel-port ? Thanks for your help in advance !! Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
s/foreach/??/g
Hi, I am currently almost done with my current job. As I am reviewing my scripts the foreach-loop started to anoy me. I am afraid this is slowing down the script. Does anyone know a faster way to do the following : # -- open(FH, "< $groupfile"); @usrs = ; close FH; $htusr = (grep {/htuser: /} @usrs)[0] ; $phi = (grep {/phil: /} @usrs)[0] ; $al = (grep {/all: /} @usrs)[0] ; @htuser = split(/ /, $htusr); @phil = split(/ /, $phi); @all = split(/ /, $al); foreach $htuser(@htuser) { chomp $htuser; if ( "$pwuser" eq "$htuser" ) { $group = "iclab"; } } foreach $phil(@phil) { chomp $phil; if ( "$pwuser" eq "$phil" ) { $group = "phil"; } } foreach $all(@all) { chomp $all; if ( "$pwuser" eq "$all" ) { $group = "all"; } } if(!($group)) { $group = "none"; } # -- Groupfile : htuser: user1 user2 user3 manyothers phil: user4 user5 manymore all: external1 external2 etc # --- I know I should have used Strict, after I reviewed everything I will try to make it strict again. You guys convinced me of using strict. It's only a pain to correct it afterwards :( Thanks for your help in advance ! Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: s/foreach/??/g
Hi Sudarsan, Sorry forgot to mention that : $pwuser = ($ENV{'REMOTE_USER'}); ## Apache var $groupfile is the group-file apache uses to authenticate. Unfortunetly there is no such thing as : $group = ($ENV{'REMOTE_GROUP'}); Therefor I have to open the file manualy and set it's $group. Any suggestions about a faster foreach ?? Regs David > > David vd Geer Inhuur tbv IPlib wrote: > > > Hi, > > > > I am currently almost done with my current job. > > As I am reviewing my scripts the foreach-loop started to anoy me. > > > > I am afraid this is slowing down the script. Does anyone know a faster way to > > do the following : > > > > # -- > > open(FH, "< $groupfile"); > > @usrs = ; > > Always check if open succeeds with an or die "..." statement > Slurping the file in is not advisable. It will be better to loop through it > > > > > close FH; > > > > $htusr = (grep {/htuser: /} @usrs)[0] ; > > $phi = (grep {/phil: /} @usrs)[0] ; > > $al = (grep {/all: /} @usrs)[0] ; > > It is better to anchor regexes, this should be written as /^htuser:/ etc. > I guess you are trying to find the group name of an entered user (You have > not mentioned what $pwuser is, this is a guess) > > If this is true (perldoc -f getpwnam, perldoc -f getgrgid) > This piece of code should do the job for you > #!/usr/bin/perl -w > use strict; > my $grp_name = getgrgid ((getpwnam ($pwuser))[3]); > $grp_name will contain the group name > > > > > > > > @htuser = split(/ /, $htusr); > > @phil = split(/ /, $phi); > > @all = split(/ /, $al); > > > > foreach $htuser(@htuser) { > > chomp $htuser; > > if ( "$pwuser" eq "$htuser" ) { $group = "iclab"; } > > } > > foreach $phil(@phil) { > > chomp $phil; > > if ( "$pwuser" eq "$phil" ) { $group = "phil"; } > > } > > foreach $all(@all) { > > chomp $all; > > if ( "$pwuser" eq "$all" ) { $group = "all"; } > > } > > if(!($group)) { $group = "none"; } > > # -- > > Groupfile : > > > > htuser: user1 user2 user3 manyothers > > phil: user4 user5 manymore > > all: external1 external2 etc > > # --- > > > > I know I should have used Strict, after I reviewed everything I will try to make > > it strict again. You guys convinced me of using strict. It's only a pain to correct > > it afterwards :( > > > > Thanks for your help in advance ! > > > > Regs David > > > > -- > > 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]
Thanks s/foreach/??/g
I really have to thank you all !! I got so many replies, with hardcore answers. I need some time for that. But I really apreciate all of your excellent help ! Regs David One day, I hope to be as good as the best... One day.. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checking environment variables...outputting to file
Hi, There should be many ENV that would only be set if you are using a browser, but one of them might be HTTP_USER_AGENT. Here is a tested example : # if($ENV{'HTTP_USER_AGENT'}) { print "Content-type: text/html\n\n"; print " You are using a browser"; } else { print "You have started this script from the command prompt \n"; } # Good luck !! Regs David - > Hi, > > I thought of another way possibly...of doing this. > > Is there a way through environment variables (or someother way) to check to > see if the perl script is being run via command prompt or from a browser > (web interface)? > > This way if someone runs the script from a command prompt I output it to > the screen using >CON: and if its run from a web browser then I redirect it > to a file and then read that file to the browser after completion > using >output.txt". > > Please say yes...and how? > > > > > >+---+ > > Philip Humeniuk > [EMAIL PROTECTED] > [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]
More efficient ??
Hello, Last time I got so much feedback that I will try it again. I learned a lot of the last recommendations, but the next issue could not be made more efficient by me. Can you ? #!/usr/local/bin/perl # my $base = "/user/IPlib/IPlib/Analog_CMOS/Camera"; ## Set temporarily for this test, normaly the user switches the $base depended on which folder he clicks. my $href = "comic_a2"; ## Set temporarily for this test, normaly this is a foreach of a directory($base) content, only if ( -d ...) are used. if ( -e "${base}/${href}/user.perm" ) { open(USERS, "< ${base}/${href}/user.perm"); while() { if ( m/^user:/ ) { my $user = (split, /:\s*/)[1]; our @users = split(/,/, $user); next; } # End if $user if ( m/^group:/ ) { my $grp = (split, /:\s*/)[1]; our @grp = split(/,/, $grp); next; } # End if $user if ( m/^descr:/ ) { my $dgrp = (split, /:\s*/)[1]; our @dgrp = split(/,/, $dgrp); next; } # End if $user } # End while } # End if -e else { @users = "niets"; @grp = "niets"; @dgrp = "niets"; } close(USERS); # user.perm: user: one,two,three group: grp1,grp3 descr: grp1,grp2,grp3 #--- What am I doing out here ? Well as I showed in my previous case I log in using apache and then determine the group that was used to log in. Now I am listing a directory($base) in a browser and each directory($href) in that directory($base) will be checked for the file user.perm, if this file excists it needs to be opened to find out the permissions of a document in that directory. F.Y.I. A bit further in the script it is used to verify if the current $pwuser is allowed to view only the description/the complete document or nothing at all. But as the script is quiet large I will send only this little piece. If you are interested I can send you the complete private. Your help is much apreciated !! Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Simple Substitution
Nope, open(CONFIG, "< /home/mnorris/$first_file") || die "Sorry, I couldn't READ /home/mnorris/$first_file\n"; while () { s//$first_var/; push @newdata, $_; } close(CONFIG); open(NEWCFG, "> /home/mnorris/$first_file") || die "Sorry, I couldn't WRITE to /home/mnorris/$first_file\n"; print NEWCFG @newdata; close(NEWCFG); Might be one of the many solutions. Good luck. Regs David > This should work, shouldn't it? > > open(CONFIG,">>/home/mnorris/$first_file") || die "Sorry, I couldn't create >/home/mnorris/$first_file\n"; > while () { > $_ =~ s//$first_var/; > } > close(CONFIG); > > It should be opening the file named "$first_file" (created earlier in the script) >and then substituting the value of "$first_var" every time it finds "" in the >file. I must be a little off course, though. > > _ > Surf on! Get a free and secure email account and more @ surfOrbit.com > http://www.surfOrbit.com > > _ > Promote your group and strengthen ties to your members with [EMAIL PROTECTED] by >Everyone.net http://www.everyone.net/?btn=tag > > -- > 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: modify UID in /etc/passwd file ?
HI Frank, You can use this one : #!/usr/local/bin/perl my $file = "/etc/passwd"; my $temppwfile = "/etc/tmppasswd"; $teller = 5000; open(PW, "< $file"); open(NEWPW, ">$temppwfile"); while () { ($user, $pw, $uid, $grpid, $descr, $home, $shell) = split(/:/); $newline = "${user}:${pw}:${teller}:${grpid}:${descr}:${home}:${shell}"; print NEWPW $newline; $teller++; } close(PW); close(NEWPW); Make sure you don't overwrite him at once, please first check the new file !!! You off course can only do this as root. Preferably I would be making a copy of the /etc/passwd-file first and work with that. Be aware of a possible (last)NIS-entry(s), those doesn't need a >5000 number in it's entry. And make sure to not change the "lp, root, adm, etc.." That will make your life real hard you see. Good luck, and be carefull !! (it is tested) Regs David - > > Hi > > I need a script that modify the UID field in a /etc/passwd file > for UNIX > > the purpose is to change the existing UID field from a start number (Eg 5000 ) > for the first line then do UID + 1 for the next line etc etc until EOF > > Thanks > > > > -- > 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: My script can't upload the data
Hi, It looks like some stuff is mixed up. Who is what ?? $foto ?? $path/$number/$foto ?? Let's make this difference : if($picture) { ## If possible of course open(F, ">$path/$number/$foto") || die "Cannot open $!"; Now what do you want to store into this file. You opened the file in overwritemode so you can never read input from it. The notation would be incorrect by then, but that doesn't matter now. I've never heard of a while($file) unless you substitute $file that makes it changing But I don't think this is what you want. while() { ## Maybe ?? print F $_; } Can you please explain where you get your input from and what it contains. Where you want to store it. Regs David > > Hello! > > The following part of code uploads 0k. > > #!/usr/bin/perl > > ... > > if($foto) { > open (F, ">$path/$number/$foto") || die "Cannot open $!"; > while(<$foto>) { > print F $_; > } > close F; > } > > Where could be the problem? > > Please help, > Collette. > > > > > -- > 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: Web client & JavaScript
Hi, I have no-one seen responding to your e-mail. I have done some tricks to submit a form with a href link and I have a solution to change the location, by just adding an extra value to it. I don't know how your external page looks up incoming vars, but you might want to test it in post and get. I won't create your script, but you at least might have an example; if($admin) { $dl = "Delete /"; $edi = "Edit "; print < function SubmitForm() { var loc = window.location; var noc = loc + "?delete=on"; var decision = confirm("Are you sure to delete this IP-Block ?"); if (decision == true){ document.location = noc } } function SubmitEdi() { document.edi.submit(); } # - > > I want to write a script that will: > 1) Go into a website, answer to a login form (JavaScript) > 2) Answer to another Form and submit it (JavaScript) > > I'm kind of novice in perl. > > 10x in advance. > > > > -- > 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]
if-statement and grep in one go
Hi, I need some help on the following. In my script I show users some infodocs after they are verified to be valid users. Users can have the permissions following the ruleset: - user (all perm) - group (all perm), - descr (Not allowed to actualy open this document). Now I do the following in my script : # - open(FILE, "< ${dir}/user.perm"); my @users = ; close FILE; chomp (@users); my @out = grep {/$pwuser/} @users; my @out1 = grep {/$group/} @users; if ((!(@out)) && (!(@out1))) { print "Sorry $pwuser you have no acces to this IP-Block"; exit; } # -- But if a user with description access enters the complete link right now, he can view the entire document. Anyway, How do I build in an if-statement in here ?? I know I can change the foreach loop and build the if statement within the loop, but isn't there something like : my @out = if (m/user:/) { grep {/$pwuser/} } @users; ## This doesn't work my @out1 = if (m/group:/) { grep {/$group/} } @users; ## This doesn't work an example of the file user.perm would be : user: vdgeerd, tester group: none, descr: all, -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading File
I am try-ing to work something out with seek for you, but just can't find it yet. This is how far I am yet : #!/usr/bin/perl use strict; my $file = "..."; open(FH, "<$file"); seek(FH,2,2); my $curpos = tell(FH); $_ = ; my $lastline = ; close(FH); print "$lastline \n"; print "$curpos \n"; # -- As the seek brings me to the end of the file at the last character I cant print the current line. I will be looking further, there must be a beatifull way to do this. Regs David > > open (FILE, "yourfile.txt"); > my @FD = ; > close (FILE); > > my $lastline = $FD[$#FD] > > Hope this help, > Smiley Connie =) > > > - Original Message - > From: "Karen Liew Ying Ping" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, June 24, 2002 6:05 PM > Subject: Reading File > > > Hi, > > Let's say I'm opening a file. > How do I read the last line of the file? > is there any function in doing so? > > Thanks. > > > > > -- > 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: Reading File
Hi, I added one. The seek didn't work. I don't have the ReadBackwards, but at least some timeing results : Benchmark: timing 1 iterations of complete, frk, pop... complete: 21 wallclock secs (16.93 usr + 0.80 sys = 17.73 CPU) @ 564.02/s (n=1) frk: 83 wallclock secs ( 1.34 usr 9.98 sys + 20.70 cusr 39.90 csys = 71.92 CPU) @ 883.39/s (n=1) pop: 18 wallclock secs (15.14 usr + 0.76 sys = 15.90 CPU) @ 628.93/s (n=1) # #!/user/cadiclab/bin/perl use strict; use Benchmark; my $file = "tst.cgi"; sub pop { open(FH, "< $file") or die "Problems opening file $! \n"; my @lines = ; my $lastline; while (my $line = pop @lines) { $lastline = $line; last; } } # End sub pop # #sub readb { #use File::ReadBackwards; #my $bw = File::ReadBackwards->new( $file ) or die "Cannot read $file: $!"; #my $last_line = $bw->readline; #} # sub frk { my $last_line = `tail -1 $file`; } # sub complete { open FILE, $file or die "Cannot read $file: $!"; my $last_line; $last_line = $_ while ; } timethese (1, { pop => \&pop, frk => \&frk, complete => \&complete }); #readb => \&readb }); # --- > > Karen Liew Ying Ping wrote: > > > > Hi, > > Hello, > > > Let's say I'm opening a file. > > How do I read the last line of the file? > > is there any function in doing so? > > > use File::ReadBackwards; > my $bw = File::ReadBackwards->new( $file ) or die "Cannot read $file: > $!"; > my $last_line = $bw->readline; > > # OR > > my $last_line = `tail -1 $file`; > > # OR > > open FILE, $file or die "Cannot read $file: $!"; > my $last_line; > $last_line = $_ while ; > > > > 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]
RE: if-statement and grep in one go
Hello, Thanks for the solution Bob. Changed some stuff and have 2 questions open. my $line; my (%u, %g); open(FILE, "< ${dir}/user.perm") or print "Failed opening file $!"; ## 1 while ($line = ) { ## 2 if ($line =~ /^user:/) { $u{$_} = 1 for split(/,/, substr($line, 6)); ## 3 } if ($line =~ /^group:/) { $g{$_} = 1 for split(/,/, substr($line, 7)); ## 4 } } close(FILE); print "Invalid login"; exit unless $u{$pwuser} || $g{$group}; ## 5 1) I don't like to die in my script as there are many files to read. And if I can't open the current file I just want to continue with the rest of the files So I always prefer printing. 2) while my $line () didn't work, just a notation error. 3) I don't need to split on spaces. The script that fills the user.perm is designed to always : "user: vdgeerd,and,other ## Never mind. BUT, What do you do with the <1> ?? Changing it to $1 doesn't matter too. I keep empty places when doing a " foreach my $value(%u) { print $value; } " chomp %u; didn't work either. 4) Same as 3 5) I changed the && into || cause the user can have acces due to group or user rights. BUT, how do I combine a printing error message and an exit within the unless ? Right now it always prints, and only exits when I have no permissions. Thanks for all your previous help!! Regs David > > > > > > > > Hi, > > > > I need some help on the following. > > In my script I show users some infodocs after they are > > verified to be valid users. > > Users can have the permissions following the ruleset: > > - user (all perm) > > - group (all perm), > > - descr (Not allowed to actualy open this document). > > > > Now I do the following in my script : > > > > # - > > open(FILE, "< ${dir}/user.perm"); > > my @users = ; > > close FILE; > > chomp (@users); > > > > my @out = grep {/$pwuser/} @users; > > my @out1 = grep {/$group/} @users; > > if ((!(@out)) && (!(@out1))) { print "Sorry $pwuser you have > > no acces to this IP-Block"; exit; } > > # -- > > > > But if a user with description access enters the complete > > link right now, > > he can view the entire document. > > Anyway, How do I build in an if-statement in here ?? > > I know I can change the foreach loop and build the if > > statement within the loop, > > but isn't there something like : > > > > my @out = if (m/user:/) { grep {/$pwuser/} } @users; ## This > > doesn't work > > my @out1 = if (m/group:/) { grep {/$group/} } @users; ## > > This doesn't work > > > > an example of the file user.perm would be : > > I think you need to parse this file into some structures rather > than using the simple regex approach. Even if you check only the > user: line, your logic would allow user names like 'user', or 'v', > or ',' or even ''. > > I would do something like this: > > my (%u, %g); > open(FILE, "< ${dir}/user.perm") or die $!; > while my $line () { > if ($line =~ /^user:/) { > $u{$_} = 1 for split(/\s*,\s*/, substr($line, 5)); > } > if ($line =~ /^group:/) { > $g{$_} = 1 for split(/\s*,\s*/, substr($line, 6)); > } > } > close(FILE); > > Now you can check for a valid user/group like this: > >print "Invalid login" unless $u{$user} && $g{$group}; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
search-engine, searching for 2 words
Hello, I am currently working on a search-eingine for .txt files I am searching for $word in each .txt file. Now of course the ability to search for 2 words in the document, must become possible. Does any of you have an idea how to compare two hashes for the same entries ? I will show you : # find(\&files, $directory); # --- sub files { my $file = $File::Find::name || shift; next if($file =~ "ref.txt"); if ( $file =~ /\.txt$/ ) { open (FILE, $file); while () { $_ = lc ; if(m/$word/) { $results{$file}= $_; } } # End while } } # end sub files In here I will just have to build in a second : if(m/$second/) { $other{$file}= $_; } After this I change the lines to become html-minded the way I want it. I can of course do the same for %other and push it into @insecond. sub subst { for (sort keys %results) { s!/[^/]*\z!!; my $link = '/' . (split (/\//, $_, 4))[-1]; ($href = $_) =~ s(^.*/) (); push @in, "$href $link "; } } # End sub subst Make @in and @insecond uniq : sub uniq { my %saw; @out = grep(!$saw{$_}++, @in); } # End sub uniq And then of course print it : print "$_" foreach @out; But how do I print only those entries that excist both in @out and @outsecond ?? So in short : I want to match 2 words within .txt documents, if the document contains BOTH words I'dd like to print it. Your help is much apreciated !! Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Permission denied on a directory
This is maybe not your only error. Of course you have to store contents of a directory like : sub getfiles { opendir(DIR, $base) or die "can't open $base : $!"; my @files = grep !/^\.\.?$/, readdir(DIR); # Extract the . and .. file closedir(DIR); } # End sub getfiles But if you created the directory's manualy, as for example root. Your directory will look like : drwxr-xr-x 28 root root 2048 Jun 26 08:48 /data/homewww/../balginst/Bilder So apache ( ps -ef | grep httpd OR look at httpd.cong to de var USER) will probably not run as root. You'd better change the permissions to 0775 and set the group permissions to the group apache is running as ( look in httpd.conf for GROUP ). Or you just "chown wwwuser directory" and leave the permissions as they are. Good luck. Regs David > > > Hello! > > (2) > > $path="/data/homewww/../balginst/Bilder"; > > open(DIR, ">$path.$fname") or die > > binmode(DIR); > > > > The code writes data in the directory balginst and always writes Bilder and >Bilder.$fname. When I > > write $path/$fname, I get an error message Is a directory. What am I doing wrong? > > > > To open a directory use > opendir DIR, $dirname; > > Greetings, > Janek > > > -- > 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: send to new page?
Hi Dennis, I solved this using Javascript. The following will show you how to open a new window for you : my $thanks = "http://..";; print " "; Maybe not exactly what you want. But the following will submit your form and then change the location : # function Thanks() { document.edi.submit(); window.location="http://mypage.com/thanks.htm";; } Hello, please press the button to submit and than go to my thanks page # -- Also a popupbox might be nice not ? Just put it somewhere you want the popupbox to be activated : alert("Thanks for submitting"); Of course you can change the window.location within the fuction Thanks with the alert. Or : function Thanks() { var decision = confirm("Are you sure to submit ?"); if (decision == true){ document.edi.submit(); alert("Thanks for submitting"); window.location="http://mypage.com/thanks.htm";; } } Last note, Functions should be placed in the header
Re: search-engine, searching for 2 words
Hi Robert, Looks good, but doens't work :) The if-statements work fine within the while-loop. After that you do something I realy don't get and my perl either :) It start complaining : Use of uninitialized value in numeric ge (>=) at /user/web/apache/cgi-bin/IPlib/1 line 88, line 471 Any idea, what goes wrong ?? Maybe you can give me a litlle more explenation ?? Hope you have the time for it. B.T.W. @matches is completely empty. Regs David # --- > > > So in short : > > I want to match 2 words within .txt documents, if the document contains BOTH words >I'dd like to print it. > > I am assuming you mean strings, whereas a word would be surrounded by space >ala: /\s$word\s/. To rephrase what you want a little, you want to track how many >times string one is found in a file, track how many times string two is found in the >same file, and keep the file only if both strings are found in the file. > > while () { > if ($_ =~ /$string1/i) { > ++$found{$file}{1}; > } > > if ($_ =~ /$string2/i) { > ++$found{$file}{2}; > } > } > > if ( ($found{$file}{1} >= 1) && ($found{$file}{2} >= 1) ) { > push(@matches, $file); > } > > Each filename must be unique, since they are used as the keys for the hash. > > > =-= Robert T. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: search-engine, searching for 2 words
Hi Robert, Thanks! This wasn't the clue that solved my problem, but it works now. I had the third if-statment placed in a different routine uniq(). Never thought of it to place it within the while loop. which was necesary (of course !!). This is how it looks right now : ... find(\&files, $directory); # --- sub files { $file = $File::Find::name || shift; next if($file =~ "ref.txt"); if ( $file =~ /\.txt$/ ) { open (FILE, $file); while () { $_ = lc ; $found{$file}{1} = 0; $found{$file}{2} = 0; if ($_ =~ /$word/i) { ++$found{$file}{1}; } if ($_ =~ /$second/i) { ++$found{$file}{2}; } if ( ($found{$file}{1} >= 1) && ($found{$file}{2} >= 1) ) { push(@matches, $file); } } # End while } } # end sub files Thanks a lot for your help !! Regs David > > It sounds like either use strict or use warnings (-w on the shebang line) is causing >the error. If you add: > > $found{$file}{1} = 0; > $found{$file}{2} = 0; > > before the two if's, that should suppress the error message (hopefully). > > What I think was happening is that one of the strings never matched, and >therefore either the {1} or the {2} did not get incremented at all. When the >greater-than-or-equal ( >= ) tried to compare a variable that did not exsist, the >'strict' or 'warning' gave an error. The fix above initializes each variable to zero, >so hopefully this will satisfy 'strict' or 'warnings'. > > The gist of the last logic is to check each counter and if both are positive, >we have a match (don't we?). So, we compare the first counter, $found{$file}{1} and >check if it's >= to 1: ($found{$file}{1} >= 1). We do the same thing with the second >counter: ($found{$file}{2} >= 1). Since you were looking for a match only if both >strings were found, we want to make sure test1 and test2 above are true in our if >statement: if ( (test1) && (test2) ) { code }. If both are true, we want to record >the $file that matched, so we push the file name onto the @matches array: >push(@matches, $file). > > Hope this helps, > > =-= Robert T. > > > On Wed, Jun 26, 2002 at 02:07:39PM +0200, David vd Geer Inhuur tbv IPlib wrote: > > > > Hi Robert, > > > > Looks good, but doens't work :) > > > > The if-statements work fine within the while-loop. > > After that you do something I realy don't get and my perl either :) > > > > It start complaining : > > Use of uninitialized value in numeric ge (>=) at /user/web/apache/cgi-bin/IPlib/1 >line 88, line 471 > > > > Any idea, what goes wrong ?? > > Maybe you can give me a litlle more explenation ?? Hope you have the time for it. > > B.T.W. @matches is completely empty. > > > > Regs David > > > > # --- > > > > > > > > > > > So in short : > > > > I want to match 2 words within .txt documents, if the document contains BOTH >words I'dd like to print it. > > > > > > I am assuming you mean strings, whereas a word would be surrounded by space >ala: /\s$word\s/. To rephrase what you want a little, you want to track how many >times string one is found in a file, track how many times string two is found in the >same file, and keep the file only if both strings are found in the file. > > > > > > while () { > > > if ($_ =~ /$string1/i) { > > > ++$found{$file}{1}; > > > } > > > > > > if ($_ =~ /$string2/i) { > > > ++$found{$file}{2}; > > > } > > > } > > > > > > if ( ($found{$file}{1} >= 1) && ($found{$file}{2} >= 1) ) { > > > push(@matches, $file); > > > } > > > > > > Each filename must be unique, since they are used as the keys for the hash. > > > > > > > > > =-= Robert T. > > -- > 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]
Regex question again
Hi, Can you please assist. I am stuck on a regex again. my $dir = "/user/IPlib/and/many/other/dirs"; $dir =~ s!/[^/]*\z!!; Will make : $dir = "/user/IPlib/and/many/other"; ## so it takes off the last dir But how do I let it make : $dir = "/IPlib/and/many/other/dirs"; ## But now on the first dir Can't find my way on regex. Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: calling shell script from perl
Hi, To open a file for reading do : open(CRONJOB, "< /home/queue/test.sh"); @data = ; close(CRONJOB); print @data; To execute a file do : system("/home/queue/test.sh", $return); or: exec("/home/queue/test.sh"); Regs David > > Hi guys, > > I need to call shell executable from a perl command, > and here is what I do: > > open CRONJOB, "/home/queue/test.sh|" or die "Unable to > open test.sh command: $!"; > > Unfortunately, neither tesh.sh executed nor I get > "Unable to open test.sh" error message. > > Does anyone know whats the problem is? > > Thanks a lot! > > __ > Do You Yahoo!? > Yahoo! - Official partner of 2002 FIFA World Cup > http://fifaworldcup.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]
make yp oneliner
Hi, Does anyone know how to make it a one-liner ?? @regel = split(/ /, `ypmatch IPlib auto.setuser`); chomp @regel; If anyone has suggestion to use NIS within Perl that is welcome also (with examples :). Regs David -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: make yp oneliner
Yep, but perl doesn't want to : Can't modify split in chomp at ./1 line 3, near ") )" Execution of ./1 aborted due to compilation errors. -- #!/user/cadiclab/bin/perl -w chomp ( @regel = split(/ /, `ypmatch IPlib auto.setuser`) ); print "hhh${_}hhh \n " foreach @regel; --- Regs David - > you should have seen this one coming. > > chomp( @regel = split(/ /, `ypmatch IPlib auto.setuser`) ); > > > -Original Message- > > From: David vd Geer Inhuur tbv IPlib > > [mailto:[EMAIL PROTECTED]] > > Sent: Monday, July 01, 2002 10:25 AM > > To: [EMAIL PROTECTED] > > Subject: make yp oneliner > > > > > > > > Hi, > > > > Does anyone know how to make it a one-liner ?? > > > > @regel = split(/ /, `ypmatch IPlib auto.setuser`); > > chomp @regel; > > > > If anyone has suggestion to use NIS within Perl that is > > welcome also (with examples :). > > > > > > Regs David > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > The views and opinions expressed in this email message are the sender's > own, and do not necessarily represent the views and opinions of Summit > Systems Inc. > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: df hang inside script
Hi Deb, Did you ever think of : open(FH, "< /etc/mnttab"); The only thing a df (or bdf) does is catinating the /etc/mnttab and checking if the "link" is still there. This way a hang of a stale nfs-mount won't bother you, but you will be able to filter it out in the mnttab as it cleary sets an error at the stale nfs-mount line. It also will save you much time forking and performing a systemcall. Good luck. Regs David > > Hey Folks, > > Recently I had a problem where a *nix system NFS was hung on a server > which had "gone away," but the client hadn't umounted the filesystem. > > Later, this caused a script in cron to fail, in that a df command inside > the script never completed, and instead it "hung," causing the script > to hang awaiting a completion of df, which it never got. > > 999 times out of 1000 this has not failed, but when that one time > comes along, all hell breaks loose. > > I'm not sure what approach to take to alleviate the cascading failure. > I'd prefer to just abort the df, log the error, and complete the rest > of the script. Short of totally re-writing the script (it's not mine, > to begin with), I would like to modify it. It's a simple system command > being used: > > system ("/usr/sbin/df -kl"); > > > Ideas? > > Thanks, > > deb > > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > "Press any key... no, no, no, NOT THAT ONE!!!" > > ô¿ô > ~ > > -- > 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: Validate linux user
Hi, I hope you are using apache. If so, can easily let apache do the authentication, just set the following in your access.conf : AuthName "RESTRICTED ACCESS" AuthType Basic require group htuser and others AuthUserFile /user/web/apache-1.3.20/Security/myapp/users AuthGroupFile /user/web/apache-1.3.20/Security/myapp/groups You can easily read the username using : $username = ($ENV{'REMOTE_USER'}); Hope this is of any help. Regs David > > > > > > Hi, again > I am looking for help to validate a linux user. > I mean, the user, writes username and password and the script returns true or > false if login is correct or incorrect. > > Please help me > > Thanks a lot. > > Bye. > > > > > > > > > > > > - > This mail sent through IMP: http://horde.org/imp/ > > -- > 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]