Re: find and replace all occurance of the string from a list of files

2004-12-08 Thread Tor Hildrum
On Wed, 8 Dec 2004 15:22:39 +0530, Chandrakant Reddy
<[EMAIL PROTECTED]> wrote:
> Hi
>
>I want to replace all occurances of  'and' with '&' in all the given files

In-place with backup in filename.bk:
perl -pi'*.bk' -e 's/\band\b/&/g' filenames

>  Here the problem is the files are owned by different users with
> different permissions. But now all the files are owned by root and
> also many of the files  with changed permission. i don't want to
> change the original ownership and permission of the file.

Run your script as root?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: I am looking for a free perl compiler.

2004-12-08 Thread Tor Hildrum
On Wed, 8 Dec 2004 15:26:58 -0500 (EST), Chris Devers <[EMAIL PROTECTED]> wrote:
> On Wed, 8 Dec 2004, Octavian Rasnita wrote:
> 
> > So the conclusion is that perl code cannot be really hidden (for
> > comercial purposes)?
> 
> For any purposes, yes, code cannot be hidden.

It can be hidden, but it will always be possible to reverse engineer
it's mechanics back.
 
Here is a silly example of a wrapper:
int main(void)
{
  FILE *fp;

  fp = fopen("./perl.pl", "w");

  fputs("#!/usr/bin/perl\nprint\"Hello World\\n\"", fp);
  fclose(fp);
  chmod("./perl.pl", 755);
  execve("./perl.pl", NULL, NULL);
  remove("./perl.pl");

  return EXIT_SUCCESS;
}

The code is somewhat hidden after compilation, but it can still be
found if you have access to the machine it's running on.

You could write a wrapper that holds the key to your encrypted
source-code, and have that wrapper decrypt it before running it. Your
code is somewhat hidden, but can be found in RAM at runtime. And, it
can be reverse-engineered like everything else.

> If you don't want someone seeing how your code works, don't let them
> have access to the machine on which your code runs.

This is the only solution. Obscurity can only get you so far.

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: want to get the count of rows of a table from oracle database using perl script

2004-12-09 Thread Tor Hildrum
On Wed, 8 Dec 2004 22:49:25 -0800 (PST), Priyanka krishnaraj
<[EMAIL PROTECTED]> wrote:
> Hi All
> 
> I want to get the count of rows in paticular table of the oracle database. 

You want DBI and DBD::Oracle.

http://www.orafaq.com/faqperl.htm

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Write to file and tty from same print call

2004-12-12 Thread Tor Hildrum
On Sun, 12 Dec 2004 15:33:44 -0600, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:

> Trying to see something of how it works:
> 
> #!/usr/local/bin/perl -w
> use IO::Tee;
> my ($handle1, $handle2);
> $handle1 = "./one"
> $handle2 = "./two"
> $tee = IO::Tee->new($handle1, $handle2);

I have never used this module before in my life, but are you sure
$handle1 and $handle2 aren't supposed to be refs to actual
File-Handles?

ie
my $handle1;
my $file = "/foo/bar/file.txt";

open($handle1, $file) or die("Can't open $file: $!\n");

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Write to file and tty from same print call

2004-12-12 Thread Tor Hildrum
On Sun, 12 Dec 2004 19:32:53 -0600, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:

> Yeah, probably something like that but what else needs to be in there
> to make the example work?

Wild guess:

#!/usr/bin/perl
use IO::Tee;

open($handle1, "file1") or die("No!");
open($handle2, "echo") or die("No2!");

$tee = IO::Tee->new($handle1, $handle2);

print $tee "Hello world!";

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: remote database access in perl

2004-12-13 Thread Tor Hildrum
On Mon, 13 Dec 2004 17:55:12 +0500, Adam Saeed <[EMAIL PROTECTED]> wrote:
> I have written a simple program that should get data from a remote
> database, but it is not working giving error:
> DBI->connect(sugs:192.168.14.2) failed: Host 'www.sample.com' is not
> allowed to connect to this MySQL server at testbug.pl line 12

Are you sure this is a perl problem and not a mysql problem? Try
connecting to it remotely from the same host using mysql(not trough
perl). You should get the same error.

I believen you want to look at the MySQL GRANT command.

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: A question about flock()

2004-12-13 Thread Tor Hildrum
On Tue, 14 Dec 2004 11:03:56 +0800, Shu Hung (Koala) <[EMAIL PROTECTED]> wrote:
> Hello,
> I wrote a script which involved writing a file, which may als be writing
> by another script. To prevent crashes, I want to used the flock() function.
> 
> my question is:
> How do I check if a file is locked by other script or I simply can't read?

You try to lock the file, and check the return status of flock().

   flock FILEHANDLE,OPERATION
   Calls flock(2), or an emulation of it, on FILEHANDLE.  Returns
   true for success, false on failure. 

flock(FILEHANDLE, OPERATION) or die("Can't flock! $!\n");

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: any perl project ideas

2004-12-14 Thread Tor Hildrum
On Tue, 14 Dec 2004 23:10:48 -0800 (PST), Harbhajan Julka
<[EMAIL PROTECTED]> wrote:
> Hey all,
> Need some pointers to perl projects that use all the
> major functionalities of perl. Please pass your ideas
> as soon as you can. I've been working on perl in
> theory and tried some small programs to practice, but
> need something bigger that would help understand perl
> and learn it too.

Write a spam-filter.

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: return value for associate array

2004-12-16 Thread Tor Hildrum
On Fri, 17 Dec 2004 15:23:35 +0800, Khairul Azmi <[EMAIL PROTECTED]> wrote:

Hi, start your script with:
#!/usr/bin/perl -w
use strict;

> sub get_conf {
> my $local_file = $_[0];
> my @local_conf;

local_conf is an array. An assosiative array in Perl, is called a hash. 
You declear it with:
my %hash;

> if (open (INFILE, "$local_file")) {
> while () {
> my $line = $_;
> 
> # if line is not a comment
> if ($line !~ /^#|^\s/) {
> my @conf_fields=split(/\s+/,$line);
> if ( $conf_fields[0] eq "var" ) {
> $local_conf[$conf_fields[1]] = $conf_fields[2];

This is array subscription. What you really want is:
hash{key} = value

Basically:
my %hash;

get various $keys and $values in loop
then set $hash{$key} = $value;

> }
> }
> }
> close (INFILE);
> 
> print "A. $local_conf{'word1'} \n";
> print "B. $local_conf{'word2'} \n";

You can't use an array like that, and you shouldn't use a hash like
that. Hardcoding the 'keys' you are getting dynamically is poor
design.

This is better, or you could use Data::Dumper
foreach (keys %hash) {
   print "$_ -> $hash{$_}\n"
}

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: control loop question

2004-12-14 Thread Tor Hildrum
On Mon, 13 Dec 2004 14:46:13 -0800 (PST), Christopher Spears
<[EMAIL PROTECTED]> wrote:
> Hi!
> 
> Let's say I have a text file filled with:
> 
> stuff
> stuff
> stuff
>   Users sometext
>   tom
>   dick
>   harry
>   Users more sometext
>larry
>curly
>moe
>moe
> stuff
> stuff
> etc.
> 
> I need to write a Perl script that will go through the
> file and find the lines with Users, process that line,
> and then start looking for moe (who may occur more
> than once).  Upon finding another line with Users, the
> code should loop and process the line and then start
> looking for moe again.  How should I proceed?  

You text example leaves something to the  imagination. 
>From the text above, and your requirements, it seems like
you can just search the whole file for 'moe'. When does
a 'Users'-part end? I'm guessing occurences of 'moe' outside
a "Users"-part shouldn't be handled?

Not really sure if this a valid way to do it, I've never nested reads on 
the same filehandle myself. 

## loop over file
while(  ) {

   ## Check for users part
   if ( /Users/i ) {

  ## Loop over users part (Is this considered bad form?)
  while(  ) {

 ## Check for end of Users
 last if /endofUserspart/;

 ## Check for moe
 if ( /moe/i ) {
## We have moe inside users
 }

  }
  
   }

}

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Execute a perl array

2005-01-12 Thread Tor Hildrum
On Wed, 12 Jan 2005 08:55:14 +0200, Groleo Marius <[EMAIL PROTECTED]> wrote:
> Hi list! ( as usual )
> i have a simple question : how can i execute an array, knowing that it
> contains perl code?

eval for @array;

Example:
tor% perl -e '@array = ("print \"hi!\n\"", "print \"hello\n\""); eval
for @array'
hi!
hello

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Pattern matching variables

2005-01-13 Thread Tor Hildrum
On Wed, 12 Jan 2005 17:27:46 -0700, Dan Fish <[EMAIL PROTECTED]> wrote:
> Are ALL pattern matching variables set back to undef once another m// or
> s/// expression is encountered, even if it contains no parenthized
> expressions?
> 
> For example, I would have expected $1 & $2 to be valid in BOTH print
> statements below...

   The numbered match variables ($1, $2, $3, etc.) and the related punctu-
   ation set ($+, $&, $`, $', and $^N) are all dynamically scoped until
   the end of the enclosing block or _until the next successful match_,
   whichever comes first. 

Thus:
__Successfull second pattern match__
perl -e '$foo = "hello"; $foo =~ /(l+)/; print "$1\n"; print "ok\n" if
$foo =~ /hello/; print " $1\n"'
ll
ok 

__Unsuccessfull second pattern match__
perl -e '$foo = "hello"; $foo =~ /(l+)/; print "$1\n"; print "nope\n"
unless $foo =~ /helo/; print " $1\n"'
ll
nope 
ll


Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: doubt with hash

2005-01-13 Thread Tor Hildrum
On Fri, 14 Jan 2005 12:09:03 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
> Hi All
> 
> I have a hash say. %browserType in which assume there are values...
> 
> %browserType=(
> "IE"=>2,
> "NETSCAPE"=>3,
> "FIREFOX"=>5
> );
> 
> I need to calculate one morething say percentage utilisation for each 
> browser..
> 
> ie..If IE is 2 = the percentage is calculated as (2/(2+3+5))*100
>NETSCAPE=(3/(2+3+5))*100
>FIREFOX=(5/(2+3+5))*100
> 
> and pass this in this single hash...I am new to this hash...I thought there 
> are two values possible, KEY and VALUE in hash
> is there a way I can add one more
> 
> "IE"=>2=>10
> "NETSCAPE=>3=>20
> 
> Please help
> 
> Anish

## calculate total
my $total = 0;

foreach keys (%hash) {
$total += $hash{$_};
}

## create a new hash to an anonymous array
foreach keys (%hash) {
 $percentage = ($hash{$_}/$total) * 100;
$browsertype{$_} = [$hash{$_}, $percentage];
}

## access
foreach keys (%browsertype) {
   print "Value: $_: $browsertype{$_}[0]\n";
   print "Percentage: $_: $browsertype{$_}[1]\n";
}

Untested though :)

Tor
Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Substitute Varaible

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 16:11:54 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
> Hi I need help regarding substituion of varaibles with values
> 
> Say I have a txt file (a.txt)
> 
> which has only one line:
> Hi $name

Don't think of $name as a perl variable, but as a placeholder. It
looks better if you use something like __NAME__. ie
Hi __NAME__

For substition, you simply use:
s/__NAME__/$var/;

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: CGI.pm and form creation

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 14:41:40 +0100, Mauro <[EMAIL PROTECTED]> wrote:
> I'm trying to create a little form usign CGI.pm but I get this error from 
> apache:
>  malformed header from script. Bad header=  checkbox(-name=>'usr',-checked=>1),
>  checkbox(-name=>'sys',-checked=>0),
>  checkbox(-name=>'wio',-checked=>0),
>  checkbox(-name=>'idle',-checked=>0),
>  reset(-name=>'Reset'),
>  submit(-name=>'Go!'),
>  end_form;
> };
> 
> print header,
> start_html('RRDTool CPU Usage Monitor'),
> h1('RRDTool CPU Usage Monitor'),
> print_form(),
> "Nothing to it!\n",
> end_html;

Replace the above with:

## start headers
print header, start_html("foo"), h1("bar");

print_form();

## end html
print end_html;

The problem is that print_form() is evaluated to early in the code or
something :)
 
Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Counting occurences of a char in a line

2005-01-17 Thread Tor Hildrum
Hi,

I have the following code in a script I'm writing:

foreach my $line () {
if ( 10 == ($line =~ s/,/,/g) ) {
print OUT $line;
}
}

Is this poor style? It looks a bit ugly, but I can't figure out a
better way to do it. I'm sure there is :)
The script will be reused and probably maintained by someone else. Is
there a more "standard" way of doing this?

regards

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: losing a value after chomp()

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 17:57:28 +, RichT <[EMAIL PROTECTED]> wrote:
>   Hi All,
> 
>time for me to ask dumb questions again...
> 
> I have a script, what i want it to do is scan through a Cisco
> router Config file (nicely saved in a text file already so no need for
> and SNMP), then output it to a .csv file.
> I an using the  Cisco::Reconfig; module to help me out.
> 
>   My problem is when i try to remove a charidge return from a
> variable, the value ends up blank, you will see from below i have
> tryed a few different ways to make this work, but i am lost (i suspect
> some basic Perl knowledge is missing).
>   any help would be most appreciated thank you .

chomp($var); is perfectly valid.

Try this code:

> sub getPortFromFullInterface {
>   my $part = shift;

 print "I'm inside getPortFromFullInterface(), \$part is: $part\n";
 
>   $part =~ s/^interface //g;
>   $part =~ s/ point-to-point//g;
>   $part =~ s/ multipoint//g;
 chomp($part);

>   return($part);
> };

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Forcing script to run as root?

2005-01-17 Thread Tor Hildrum
On Mon, 17 Jan 2005 14:08:10 -0500, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Worked perfectly. I knew it was something simple. Thanks!
> 
> Never used POSIX before. Looked at it on cpan but those descriptions can be
> flat sometimes. If you don't mind, what are some practical uses for it? Just
> basic OS stuff?

Yes and No. OS-stuff, but not basic.
You probably need to be a C-programmer to really miss it :)

But, usually, Perl has it's own functions that are easier or better
to use.

http://www.perl.com/doc/manual/html/lib/POSIX.html

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Counting occurences of a char in a line

2005-01-17 Thread Tor Hildrum
On Tue, 18 Jan 2005 01:08:56 +0100, Jenda Krynicky <[EMAIL PROTECTED]> wrote:

> foreach my $line () {
> if ( $line =~ /^[^,]*(?:,[^,]*){10}$/) ) {
> print OUT $line;
> }
> }
> 
> That is check whether the full string is "something not containing
> comma followed by ten times comma and something not containing
> comma".

This is a script for an awful system where I only have access to a
certain part of the whole system. It's a web-form with 10 fields.
Instead of putting
the fields directly into a database, I get the fields as a comma-seperated list
on email. One mail for each request(!). 
So, I'm basically parsing a huge mbox-file here.

I have no power over the "webmaster", and he won't listen to reason. 
The fields may or may not be empty. So, valid format is:
[EMAIL PROTECTED],bar,foo,bar,foo,bar,foo,bar,foo, bar, foo
and
[EMAIL PROTECTED],,
and
foo,bar,,,

I'm basically just checking for 10 commas, write it to it's own file
and then use a mysql-import script on that file. Any lines with more
than 11 commas get's flagged for manual checking.

To make matters even worse, "we" are using Matt's Formmail script. I'm
not sure if it's gotten better, but last time I checked it didn't have
the best of track records.

I ended up using tr//, even though it sports almost the same
readability as s// it seems more correct.

Thanks.

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: losing a value after chomp()

2005-01-18 Thread Tor Hildrum
On Tue, 18 Jan 2005 13:22:14 +, RichT <[EMAIL PROTECTED]> wrote:
> Hi again,
>   ok i made the changes sugested, but something is still wrong.
> the output im getting is
> --
> "interface is "ATM0
> "interface is "ATM0.38
> --
> 
> ie the " is at the start of the line???

> print "\$interface is \"$interface\"\n";

Uhm? I can't see anything wrong here. Might be a linefeed at the end
of $interface though.

Try this code:
$interface =~ s/\r//g;
print "\$interface is \"$interface\"\n";

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: losing a value after chomp()

2005-01-18 Thread Tor Hildrum
On Tue, 18 Jan 2005 15:15:00 +, RichT <[EMAIL PROTECTED]> wrote:

> Grate that worked, the varible must of have a \r and a \n at the end.
> thank you very much...
> 
> how would i find our what escape chars are in a varible?
> or is there a way to print out a string with out perl translating the
> escape chars?
> 
>  Thank you again, Ritchie

I believe Windows use \r\n, while most(?) *nix' use \n. 
What happened is probably that when your script runs:

 for my $found ($config->get('interface')->all($interfaceTypes)) 

$config-get.. just returns the whole line(or the last part of the line) 
from a file that has windows line-ending(\r\n).

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Retrieving data from telephone system.

2005-01-19 Thread Tor Hildrum
On Tue, 18 Jan 2005 17:04:13 -0600, Jason Balicki
<[EMAIL PROTECTED]> wrote:
> I'm looking for some help with a little project

Unless your going to ask for help with some
actual code you have written, this is better suited
for [EMAIL PROTECTED]

regards

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Cannot create the file~

2005-01-19 Thread Tor Hildrum
On Thu, 20 Jan 2005 10:45:42 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
> Hi
> 
> I  am  new to CGI..I cannot create a file using CGI. I do execute another 
> program to create a file, it executes fine..But while using CGI it fails.
> 
> I had used  a die statement and after that I tried printing some text after 
> this. it is not getting printed that means it is not printing...Please help 
> in printing out the die message,.

Where are you looking for the print-statement to output? 
It would be in your httpd_error.log file.

> I had used
> 
> en INPUT ,">a.txt" or die "Cannnot create the file $!";
> 
> The message is not getting printed and I am not aware of the reason. Please 
> help me to troubleshoot this.

Just run your script in interactive-mode from the command-line, 
and check what the output is. If your not able to figure out how to 
do that, post more of your code.

There is nothing wrong with the perl code you just posted(I'm assuming 
the 'en' is supposed to be 'open').

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Authen::SMB

2005-01-24 Thread Tor Hildrum
On Mon, 24 Jan 2005 10:09:09 +, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Morning
> 
> Do anyone know where I can get information on how this module work? I've
> search the Internet nothing so-far.

www.cpan.org would be a good place to start:
http://search.cpan.org/~pmkane/Authen-Smb-0.91/Smb.pm

Tor

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl SMS

2003-08-14 Thread Tor Hildrum
awards wrote:
Hi,

I was reading on the internet someone wanted to do sms with perl and he
couldn't
But my question is simple, can you really send SMS free of charge to
anywhere in the world.
No. You can write up a script that connects to a webpage and
does the sending for you, but you can't physically send an sms
over the internet. You need a 'device' to receive the sms and
then relay it to the recipient. These are not cheap, and also requires
access to a GSM(?) nett.
I've been looking everywhere could not find the answer.
http://www.gsmworld.com/technology/sms/intro.shtml#11

Tor



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: How to replace a long string in a text file?

2003-08-14 Thread Tor Hildrum
perlwannabe wrote:
Now that I have, with all of you helping, dealt with the unlink problem. 
I am now faced with a new problem.

I have a file, myfile.txt, that consists of various text items that are
repetitive.  I am trying to replace many of the repetitive items with a
place holder. Here is an example of myfile.txt:
From the script under you are just replacing lines with a static 
line/value.



Perhaps I am attacking this problem wrong by using hex, but it seems
easier to use then text which has carriage returns, tabs, and spaces.
I don't see any reason to use hex.
There is a common idiom to use when searching for repetitions/uniqueness.
## untested example :)
@array = qw(one two one three four);

for (@array) {
   if (defined($unique{$_}) {
  s/$_/replacement/;
   } else {
  $unique{$_}++; ## $unique{$_} is now defined and true.
}   ## and will be replaced if it comes up again
This works equally well for files, it's just a matter of s/@array//
There *might* be a question of memory usage though, depending on
the size of the file your working with.
Also, sort -u would be faster and more efficient if you have large files,
but didn't need the replacement text.
Tor

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Scope of variables. Lost in subs

2002-04-07 Thread Tor Hildrum

I have the following script:

..my $variable = "";  # Global variable, right?

if (true/false) { sub3(); }
elsif (true/false) { sub2(); }
else { sub1(); }

## The point with this, is that sub1 is always called first, then sub2, then
## sub3. This works perfectly.

sub sub1{

}

sub sub2{
$variable = param("from_sub1"); ## This param is inputed in sub1, works fine
}

sub sub3{
open (VAR, ">>$variable") or die("Can't open $variable: $!\n"); ## Fails.
}

Here are some of the error messages I get:
Use of uninitialized value in concatenation (.) at script.cgi line 55.
Use of uninitialized value in concatenation (.) at script.cgi line 55.
Can't open : No such file or directory

Any help, hints or tips would be appreciated.

Tor


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Scope of variables. Lost in subs

2002-04-08 Thread Tor Hildrum

On 8/4/02 9:15, "Tor Hildrum" <[EMAIL PROTECTED]> wrote:

> Here are some of the error messages I get:
> Use of uninitialized value in concatenation (.) at script.cgi line 55.
> Use of uninitialized value in concatenation (.) at script.cgi line 55.
> Can't open : No such file or directory

Full source for the script can be located at:
http://tortest.nuug.no/perl.txt

The script dies on this line:
open (REGISTRER, ">>$registrerte") or die();  ## $registrerte null-value

I don't understand why it is, because I have defined it at the start of my
script with my $registrerte = "";
I thought that made it global?
And, it is defined in the sub registrer().
I have also tried setting it inside the sub without luck.

Any advice would be much appreciated.
I have re-read chapter 8 of Learning Perl, but I'm not getting any wiser.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Scope of variables. Lost in subs

2002-04-08 Thread Tor Hildrum

Thanks to everyone who replied.

I got enough information to solve the problem, and then some more :)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




CGI, submit buttons, using them as variables.

2002-04-30 Thread Tor Hildrum

First of all, I would just like to apologize for not sending this to the
CGI-list, but I prefer this list. As this is where I've gotten the best help
in the past. Blame yourself :)

I was reading CGI.pm when I discovered that you could use the -value
argument from submit buttons, and assign them to variables.
>From CGI.pm:
###
submit() will create the query submission button.  Every form
should have one of these.
The first argument (-name) is optional.  You can give the button
a name if you have several submission buttons in your form and
you want to distinguish between them.  The name will also be used
as the user-visible label.  Be aware that a few older browsers
don't deal with this correctly and never send back a value from a
button.
The second argument (-value) is also optional.  This gives the
button a value that will be passed to your script in the query
string.  You can figure out which button was pressed by using
different values for each one:
 $which_one = $query->param('button_name');
##

I was thinking of ways I could use this, and tried with this idea:

my $q = new CGI;
my $buttonVelgArrangement = undef;

if  ($buttonRegistrer) { FerdigRegistrering(); }
elsif ($buttonVelgArrangement) { Registrer(); }
else { VelgArrangement(); }

sub VelgArrangement {
   print $q->start_html,
   $q->h1("here is a form"),
   ## FORM HERE
   $q->submit(-name=>'velgarrangement', value=>'Velg'),
   $q->end_html;
my $button = \$buttonVelgArrangement;
$button = $q->param('velgarrangement');
}

When I try to use this method, nothing happens when I press the submit
button. Is this method possible, or am I misunderstanding something?
I was hoping it would jump to Registrer().
Is the problem that when I hit the submit-button, a new CGI call is sent to
the server, and $buttonVelgArrangement is again undef?
Has anyone used this feature of the submit button before (in what way?)?

Any help/info is greatly appreciated.

Tor 
(I added my test code below)

-- START FULL EXAMPLE CODE
#!/usr/bin/perl
use Strict;
use DBI;
use CGI qw(:standard);

my $q = new CGI;
my $host = "localhost";
my $user = "tor";
my $password = "password";
my $database = "nuug";
my $table = "arrangement";
my $buttonVelgArrangement = undef;
My $buttonRegistrer = undef;

if ($buttonRegister) { FerdigRegistrering(); }
elsif ($buttonVelgArrangement) { Registrer(); }
else { VelgArrangement(); }

sub VelgArrangement {
my @arrangement;
my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user,
$password, {'RaiseError' => 1});
my $sth = $dbh->prepare("select * from $table");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
push(@arrangement, $ref->{'kort'});
}

print   $q->header,
$q->start_html('Registrering'),
$q->h1("NUUG Arrangementsregistrering "), hr,
$q->h3("Velg arrangement: "), popup_menu(-name=>'arrangement',
-values=>\@arrangement),
$q->hr,
$q->submit(-name=>'velgarrangement', -value=>'Velg'),
$q->end_html;
my $button = \$buttonVelgArrangement;
$button = $q->param('velgarrangement');
}

sub Registrer { 
print   $q->header,
$q->start_html('Registrering'),
$q->startform(),
$q->textfield(-name=>'navn', -default=>'Ola Nordmann', -size=>35,
-maxlength=>50),
$q->textfield(-name=>'epost', -default=>'Ola\@nordmann.no',
-size=>50, -maxlength=>50),
$q->endform,
$q->p,h1('Du valgte: '), $q->param('arrangement'),
$q->submit(-name=>'registrer', value=>'Registrer'),
$q->end_html;
My $button = \$buttonRegistrer;
$button = $q->param('registrer');
}

## I haven't done FerdigRegistrering(), since this submit-experimenting
## didn't work.

--END OF CODE


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




MySQL hangs.

2002-05-02 Thread Tor Hildrum

First my database.
[localhost:~] tor% mysql -u tor -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 3.23.42

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use nuug
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from Oslo_220602_Vika;
+-+--+
| navn| epost|
+---------+--+
| Tor Hildrum | [EMAIL PROTECTED] |
| Tor Hildrum | [EMAIL PROTECTED]  |
| Tor Hildrum | [EMAIL PROTECTED]  |
+-+--+
3 rows in set (0.00 sec)

Now the code:
#!/usr/bin/perl 
use Strict;
use CGI qw(:standard);
use DBI;

my @arrangement;
my $tabell = "Oslo_220602_Vika";
my $navn = "Tor Hildrum";
my $epost = "tor\@whatever.com";

my $dbh = DBI->connect("DBI:mysql:database=nuug;host=localhost", tor,
password, {'RaiseError' => 1 });
my $sth = $dbh->prepare("select * from $tabell");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
push(@arrangement, $ref->{'epost'});}

while (@arrangement) {
chomp;
my $test = 1 if $_ eq $epost;
}

if ($test == 1) {
  print $q->start_html,
$q->h1('Feil ved registrering'),
$q->hr,
$q->h2("$epost er allerede registrert til arrangementet: $tabell"),
$q->hr,
$q->h1('Kontakt NUUG hvis du tror det har oppstaatt en feil'),
$q->end_html;
$dbh->disconnect();
} else {
$sth->prepare("insert into $tabell('navn', 'epost') values ($navn,
$epost)");
$sth->execute();
$dbh->disconnect();

  print $q->header,
$q->start_html,
$q->h1("Registrering fullfoert"),
$q->hr,
$q->h3("Du er naa registrert til arrangement $tabell, med foelgende
informasjon: "),
$q->h3("Navn: $navn"), p,
$q->h3("Epost: $epost"),hr,
$q->end_html;
}

When I try to run this script from either the command line or from a
web-browser, it just hangs. I'm not sure how to figure this out. I can't
seem to find any mysql log-files, nor will my webservers log provide any
information, and when using the command line it justs hangs without
outputting anything. Anyone that can help me with the code, or ideas of how
to troubleshoot this? I think the problem is with MySQL, but reading man
DBI, I can't see what I am doing wrong.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: MySQL hangs.

2002-05-02 Thread Tor Hildrum

 >> Now the code:
>> #!/usr/bin/perl 
>> use Strict;
>> use CGI qw(:standard);
>> use DBI;
> 
> Honour deserved for using 'strict', but you have forgotten
> to enable warnings.  Strict ***MUST*** be lowercase otherwise
> on systems with case-sensitive filenames it will barf.
> 
>> my $dbh = DBI->connect("DBI:mysql:database=nuug;host=localhost", tor,
>> password, {'RaiseError' => 1 });
> 
> I can't remember the syntax for this, but the string looks wrong to
> my eye.

Nope, it's correct :)
 
> Don't forget to turn on autoflushing with "$|=1", or for long queries
> it will timeout.

Thanks for the tip. I guess I will find information about it in man DBI?
 
> Try using:
> 
> die "Managed to get to the waypoint!";
> 
> to find out what code is actually getting run - there is better ways,
> but this is a beginners list :)

That is great advice :)
 
The code again:
#!/usr/bin/perl 
use Strict;
use CGI qw(:standard);
use DBI;

my @arrangement;
my $tabell = "Oslo_220602_Vika";
my $navn = "Tor Hildrum";
my $epost = "tor\@whatever.com";

my $dbh = DBI->connect("DBI:mysql:database=nuug;host=localhost", tor,
password, {'RaiseError' => 1 });
my $sth = $dbh->prepare("select * from $tabell");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
push(@arrangement, $ref->{'epost'});}

while (@arrangement) {   ## HANGS
chomp;   ## HERE
my $test = 1 if $_ eq $epost;   ## HMM? :)
}

If we look at how @arrangement is created:
while (my $ref = $sth->fetchrow_hashref()) {
push(@arrangement, $ref->{'epost'});}

I know this is correct, because I am using it in another sub in the same
script(this script is just a sub that I made to be independent for
troubleshooting). 
@arrangement = qw([EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]);
That is how @arrangement should look like. And, I believe it looks like
that.

If I do:
# $sth->execute();
# while (my $ref = $sth->fetchrow_hashref()) {
# push(@arrangement, $ref->{'epost'});}
@arrangement = qw([EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]);

while (@arrangement) {
chomp;
my $test = 1 if $_ eq $epost;
}

die ("Hooray, didn't hang.");

It still hangs on the while(@arrangement) loop.

Any idea why this while loop doesn't want to quit?

Tor


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: MySQL hangs.

2002-05-02 Thread Tor Hildrum

> From: Felix Geerinckx <[EMAIL PROTECTED]>
> Date: 2 May 2002 17:55:47 -
> To: [EMAIL PROTECTED]
> Subject: Re: MySQL hangs.
> 
> on Thu, 02 May 2002 17:08:47 GMT, Tor Hildrum wrote:
> 
>> while (@arrangement) {
>>   chomp;
>>   my $test = 1 if $_ eq $epost;
>> }
>> [...] 
>> When I try to run this script from either the command line or from a
>> web-browser, it just hangs.
> 
> You are not removing anything from '@arrangement', so if it's not empty to
> start with, you have an infinite loop here.
> 
> use warnings;
> 
> or
> #! perl -w
> 
> as suggested by another poster, would have warned you with
> 
> 'Use of uninitialized value in scalar chomp',
> 
> signalling that your 'while(@arrangement)' construct is *not* equivalent
> to
> while ( defined($_ = shift(@arrangement)) )
> 
> This magic only works with
> 
> while ()

Yikes :)
Back to reading Learning Perl I guess.
Chapter 3 isn't it? :)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Another MySQL.

2002-05-02 Thread Tor Hildrum

Here is the code:
while (@arrangement) {
chomp;
if ($_ eq $epost) { my $test = 1; }
shift(@arrangement);
}

if ($test) {
## Some more Code. The if statement always fails :(

Here is what @arrangement looks like:
@arrangement = qw([EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED],
[EMAIL PROTECTED]);

My problem is that even though $epost = "[EMAIL PROTECTED]";
$test is still undef. Is this because $_ only works for while()?
I couldn't find any mention of $_ in chapter 4 of Learning Perl: Control
Structures. But, I'm pretty sure I'm way of track here.
I tried looking in perldoc perlop, but couldn't find anything there either.

Anyone know what could be wrong?

Just for fun, I added this line right before the while loop:
die ("This is \$arrangement[0]: $arrangement[0]");

The error message from apache:
This is $arrangement[0]: [EMAIL PROTECTED] at
/Library/WebServer/CGI-Executables/nuugsql.cgi line 93.

So, I feel like I'm again missing some basic thing(Both @arrangement and
$epost contains exactly what they are supposed to).. But I can't figure out
what :(

I also get this from apache:
Use of uninitialized value in scalar chomp at
/Library/WebServer/CGI-Executables/nuugsql.cgi line 95.
Use of uninitialized value in string eq at
/Library/WebServer/CGI-Executables/nuugsql.cgi line 96.

Could it be that @arrangement isn't scoped correctly?
I can access it's values before the while loop, so I wouldn't think this to
be the problem.

PS: I use $epost in another part of the sub, so I know $epost also holds the
right variable.

This will be the last one, I promise.

Any help is greatly appreciated. :)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Another MySQL. Solved by driuex :)

2002-05-02 Thread Tor Hildrum

> Here is the code:
> while (@arrangement) {
> chomp;
> if ($_ eq $epost) { my $test = 1; }
> shift(@arrangement);
> }

>From another mail written by driuex on the subject:
"is this like some new Kult thing?

It appears that this 'while' construct has popped up on both
the beginner's list and the beginner-cgi list

rather than the traditional Orthodox Perl:

foreach my $val (@array) { # note $val is scoped for this loop only
# do the jazz with $val so that when we would have done
# something have the n-method calls on objects we do not
# have to worry about what other PM's did to $_  "

foreach my $email(@arrangement) {
if ($email eq $epost) {$test = 1; }
}

Worked beautifully :)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Another MySQL.

2002-05-02 Thread Tor Hildrum

> From: Felix Geerinckx <[EMAIL PROTECTED]>
> Date: 2 May 2002 19:32:36 -
> To: [EMAIL PROTECTED]
> Subject: Re: Another MySQL.
> 
> on Thu, 02 May 2002 19:10:48 GMT, Tor Hildrum wrote:
> 
>> Here is the code:
>> while (@arrangement) {
>> chomp;
>> if ($_ eq $epost) { my $test = 1; }
>> shift(@arrangement);
>> }
>> if ($test) {
>> ## Some more Code. The if statement always fails :(
> 
> Although you 'shift @arragement;' now, you don't shift it into $_.
> You should write 
> 
> $_ = shift @arrangement;
> 
> before the 'chomp';
> 
> Further, your 'my $test' is local to the if {} block, so the
> 'if ($test)' (probably) refers to the package global $main::test, which
> is not defined. 
> 
>> I also get this from apache:
>> Use of uninitialized value in scalar chomp at
>> /Library/WebServer/CGI-Executables/nuugsql.cgi line 95.
>> Use of uninitialized value in string eq at
>> /Library/WebServer/CGI-Executables/nuugsql.cgi line 96.
> 
> I explained this in a previous post.
> 
>> This will be the last one, I promise.
> 
> If you have more questions, ask them. That's what this newsgroup is
> for. 

Yup, and you guys haven't failed me yet.
Got my first 100+ liner CGI-script to work :)
Not bad for a newbie. :)

Heck, I even learned a couple of things during the processes.

Thanks :)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: developing and testing first CGI/Perl application

2002-05-03 Thread Tor Hildrum

> From: "james" <[EMAIL PROTECTED]>
> Date: Fri, 3 May 2002 08:54:49 -0500
> To: <[EMAIL PROTECTED]>
> Subject: Re: developing and testing first CGI/Perl application
> 
> drieux,
> 
> i've been monitoring this list and couldn't help but notice the volume of
> your posts. i have to ask: do you ever sleep?
> 
> :) james

>From reading his energetic (and very helpful) posts, I would say he is high
on coffee :)

The best of all is that he is as energetic on a couple of other lists I
subscribe to as well. :)

And, if you haven't bookmarked it:
http://www.wetware.com/drieux/CS/lang/Perl/Beginners/

:)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Suid.

2002-05-03 Thread Tor Hildrum

Could someone point me to a page that gives information about all the
pitfalls that are "available" when running a Perl or CGI script with the
suid bit set?

I tried google.com, but couldn't find anything god.
I found this:
http://www-genome.wi.mit.edu/WWW/faqs/wwwsf5.html

But, it's extremely light on information.

Any help is greatly appreciated.

PS: I've seen all the "Do you really need to run your script as suid"
warnings. :)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Suid.

2002-05-03 Thread Tor Hildrum

> 
>> Could someone point me to a page that gives information about all the
>> pitfalls that are "available" when running a Perl or CGI script with the
>> suid bit set?
> 

 :)

> If you really need setuid processes - then one of the
> principle tricks remains to have them 'spawned' from a
> nice harder to hack piece of compiled 'c' code.

So, basically, call a compiled c-code from my Perl-script, and have the
compiled c-code start the suid process?

[localhost:~/pictures] tor% cc
cc: No input files
[localhost:~/pictures] tor% c++
c++: No input files

Ah :)

Now I only need to learn how to program either C or C++ :)

The WWW security faq had an example, I'll work from that.

Thanks :)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Split

2002-05-14 Thread Tor Hildrum

> From: Francesco Guglielmo <[EMAIL PROTECTED]>
> Date: Tue, 14 May 2002 14:18:18 +0200
> To: David vd Geer Inhuur tbv IPlib <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED]
> Subject: Re: Split
> 
> Many thanks!But to take it from a file and not from a variable like $line?

open FILEHANDLE, /path/file.txt or die("Error opening FILEHANDLE: $!\n");
open WRITETOFILE, >/path/outfile.txt or die();

While () {
chomp;
my @parts = split /:\s+/;
print WRITETOFILE "$parts[1] $parts[0]\n" unless @parts != 2;
} 


The file you specify as WRITETOFILE would then look like:
name username
Two names username
Three names here username

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: regexp needed

2002-05-14 Thread Tor Hildrum

> Hi, I have a file like this:
> ...
> SceInfEveryone = "Everyone"
> SceInfGuests = "Guests"
> SceInfGuest = "Guest"
> SceInfPowerUsers = "Power Users"
> SceInfPrintOp = "Print Operators"
> ..
> 
> And I wanted to extract Guest (without the quotes)i tried this:
> 
> my $HISEFILE= "c:/hisecdc.inf";
> open HISE,"< $HISEFILE"
> or die "je ne peux ouvrir $HISEFILE :$!";
>   while () {
> if (/SceInfGuest\s+:\s([0-9a-z]+);/i) {

Where does the ':' come from? And the ';'?
print $1 if (/sceinfguest([a-z])/i)

Untested though.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Timing execution of a sub

2002-05-15 Thread Tor Hildrum

Are there any tricks to time the execution of a sub?
Specifically I'm using the Fisher-Yates shuffle, using an array with a
couple of million numbers. I want to time the shuffle.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: avoid backticking if at all possible - Re: perl awk question

2002-05-21 Thread Tor Hildrum

> From: "Taylor Lewick" <[EMAIL PROTECTED]>
> Date: Tue, 21 May 2002 08:00:45 -0500
> To: <[EMAIL PROTECTED]>
> Subject: avoid backticking if at all possible - Re: perl awk question
> 
> Thanks drieux, I looked over the code you posted, most of it makes sense, but
> am still a little confused over a couple of things,
> Why are you setting $infile and $outfile to ARGV values?  I thought those were
> being past from the command line, but in this instance, I know what files I
> want to access. 

[localhost:~/Programming/Perl/Various code] tor% cat argv.pl
#!/usr/bin/perl -w
for (@ARGV) {
push @ARGV;
print "$_\n";
}
[localhost:~/Programming/Perl/Various code] tor% ./argv.pl 2 3 bananas
apples
2
3
bananas
apples
[localhost:~/Programming/Perl/Various code] tor%

You can use the $ARGV[X] values directly like above, or you can put them in
variables. I guess that's what drieux did. Everything passed from the
command line are put into to the @ARGV array.
So, when I write 
% ./argv.pl 2 3 bananas apples
@ARGV looks like this: qw(2 3 bananas apples)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Help on comparing matching two arrays

2002-05-21 Thread Tor Hildrum

> I define two arrays - one is an active changing file  ( @unix = ps -ef ) and
> need to compare it to a static text file @static = `cat myfile`.
> 
> Would someone help me on the syntax of greping for @static matches in the
> @unix array.



> I am not sure if I need to assign a variable, for loop etc with in the { }
> to get the pattern matching results I need.

I nested two foreach loops:

[localhost:~/Programming/Perl/Various code] tor% cat matching.pl
#!/usr/bin/perl -w
use strict;

my @array1 = qw(file1 file2 file3 file4 file5);
my @array2 = qw(file1 file2 file4 file5);
my @result;

foreach my $file (@array1) {
foreach my $file2 (@array2) {
   if ($file eq $file2) {
   push(@result, $file);
   }
}
}

print "@result\n";
[localhost:~/Programming/Perl/Various code] tor% ./matching.pl
file1 file2 file4 file5

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: checking for an empty string

2002-05-28 Thread Tor Hildrum

> From: lz <[EMAIL PROTECTED]>
> Date: Tue, 28 May 2002 07:08:52 -0700 (PDT)
> To: [EMAIL PROTECTED]
> Subject: checking for an empty string
> 
> Hi guys,
> 
> while($line = )
> {
>   if ($line =~ /^email address/)
>   {
>}
> }
> 
> How can I check if $line contains a value or is empty?

chomp $line; # not sure this is needed.
if ($line) {}

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Getting data from console

2002-05-29 Thread Tor Hildrum

> From: "Heiko Heggen" <[EMAIL PROTECTED]>
> Date: Wed, 29 May 2002 15:28:17 +0200
> To: "Beginners@Perl. Org" <[EMAIL PROTECTED]>
> Subject: Getting data from console
> 
> Hi.
> 
> Just another question. How can I get a user input from the console in perl?
> I'm just playing with the DBI Module and want to ask for a select statement,
> which I can enter in the console. Executing the statment works already fine
> *gg*.

Do you mean like:
print "Select what database to open:\n";
chomp(my $db = );

Or % perlscript.pl database user
Where you can access them trough $ARGV[0] and $ARGV[1]

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: probably a simple question

2002-06-05 Thread Tor Hildrum

> Is there any function to tell if a number is even or odd?
> I am looking for an easy way to loop through a list and
> output table cell bgcolor based on even / odd.
> 
> if its an even numbered row make it red if its odd make
> it blue.
> 
> I have done it in the past by turning a switch on or off
> but I think there must be an easier way.

There might an easier way, but you could always use the modulus operator.
if ($number % 2 ) {
# number is even
} else {
   # number is odd
   }

I guess you could put that in a loop to colour up your cells.

Tor 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: avoiding greedy match..

2002-06-09 Thread Tor Hildrum

> BlankHi everyone,
> 
>   I need some help for preventing greedy match..I want to get rid of the
> words in paranthesis in the below text. When i use the code below i loose '
> john '  because it matches the last ' )' after recovery.. Is there a easy
> way to avoid this?..
> 
> 
> $target='micheal (fields) john (recovery)';
> 
> $target=~s/\(.+\)/ /gi;
> 
> print $target;
> 
> output : micheal

#!/usr/bin/perl -w
use strict;

my $target='micheal (fields) john (recovery)';

$target=~s/\(.+?\)//gi;

print "$target\n";

[localhost:~/Programming/Perl/Various code] tor% ./greedy
micheal  john  
[localhost:~/Programming/Perl/Various code] tor%

This does however produce 2 spaces between the two names. So, you might also
want to match the extra space before or after the parentheses.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: $FORM in Matt's wwwboard.pl

2002-06-09 Thread Tor Hildrum

> Hi guys,
> I'm just looking at Matt's wwwboard.pl and try to figure out what the
> $FORM{somevaule} does.
> It is not declared anywhere before usage.. and I'm quite lost...
> 
> If anyone could tell me where to find any information about that, I'd
> be grateful

All though a bit OT, it is normally considered bad form to try and learn CGI
by reading Matt's code. nms-cgi.sourceforge.net probably has better code to
learn from.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: invisible syntax error

2002-06-11 Thread Tor Hildrum

> hi,
> 
> I simply wished to strip out all the ">" from a text file. below is the
> script and the error that is reported.  I cannot see anything wrong, it's
> such a simple piece of code! can any one help, are my eyes deceiving me?

[localhost:~] tor% perl -e 'while(<>) {s/\>//g; print;}'
>>1>2>>3
123
1>2>3>4>5>6>7>8>
12345678

> #!/usr/bin/perl -w
use strict;

> open(INPUT, "letter.txt") || die "can't open file: $!";
> open(OUTPUT, ">newletter.txt");
> 
> while (){
s/\>//g;
> print OUTFILE;
>   }

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Putting values into hash

2002-06-11 Thread Tor Hildrum

> read the filein...
> 
> open(FILE, $file) or die "blah blah $!";
> undef $/; ## or local $/ if in a BLOCK
> $contents = ;
> close FILE;
> 
> $contents =~ s/\\\n//g; # put everything on one line (deletes \ followed by
> newline)
> 
> foreach (split /\n/, $contents){
> ## you can figure this part out right?
> }

Since there are more than 1 param on each line, wouldn't it be:
my @array = split (/\s+/, $contents); #?

>> Parameter=Value1 Value2 Value3 \
>> Value4 Value5 Value6 \
>> Value7 Value8

After:
> $contents = ;
> close FILE;
> 
> $contents =~ s/\\\n//g;

$contents = qw(Parameter=Value1 Value2 Value3 Value4 Value5 Value6 ..); # ?

s/\\\n|\w+=//g;

?

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Reading File

2002-06-24 Thread Tor Hildrum

> could puting the entire file into an aray then i think there is a function to
> get the number of elements... then just use that to know what the last
> element would be?

my @array = ;

print "$array[-1]";

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: #!/usr/bin/perl - is there a macro for this?

2002-06-24 Thread Tor Hildrum




> It does save quite a bit of time if you write lots of scripts.
> Especially when you need a quicky to check something in a more
> complex one before adding it.

This is where you would use your one-liners.
I'm pretty sure most people here check syntax etc on a one-liner before they
post a solution.

perl -e '..' # I would think that is the 'default' time saver.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Comparing Arrays

2002-07-23 Thread Tor Hildrum

<[EMAIL PROTECTED]> wrote:

> Hi
> 
> I would like to know how to compare 2 arrays.
> 
> I have 2 arrays and I would like to compare the contents of the data.
> It doesn't matter in which order the data is stored so long as its the same.
> So comparing the bellow should read true, but if they didn't match it would
> be false.
> 
> my @foo = qw(
>   foo bar cat dog
> );
> my @bar = qw(
>  dog cat foo bar
> );

One way to do it:
#!/usr/bin/perl -w
use strict;
my @foo = qw(this that and something);
my @bar = qw(that and something this);
my @result;

foreach my $fooline (@foo) {
foreach my $barline (@bar) {
 push(@result, $barline) if $barline eq $fooline;
}
}
print "true\n" if scalar(@result) == scalar(@foo);

This does however assume text-fields in the arrays.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Replace last # with \n

2002-07-23 Thread Tor Hildrum

<[EMAIL PROTECTED]> wrote:

> I have a string that looks like
> 
> Operator Overview#PGM#Report about all configured
> operators#/opt/OV/bin/OpC/call_sqlplus.sh all_oper#
> 
> I want to replace the last "#" with a newline. I've come up with a few ideas
> like
> 
> substr ($_, rindex ($_, "#"), 1) = "\n" ;
> or
> substr ($_, length ($_) - 1, 1) = "\n" ;
> or
> chop ; $_ .= "\n" ;
> 
> Are there any better ways, maybe using s/// or tr/// ? TIA...
> 

This is horrible, but works :)
s/(.+)#(.+)$/$1\n$2/

It will always match greedy, so it will always match the last # on the line
:)

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Formatting date, time

2002-08-13 Thread Tor Hildrum

<[EMAIL PROTECTED]> wrote:
> #Insert Date and Time
> my $month = $mon00   #Two digit month
> my $day = $mday00   #Two digit day in month
> my $year = $year#Two digit year
??
> my $hour = $hour00   #Two digit: Hour
> my $min = $min00   #Two digit: Minutes
> #Combine date and time above into MMDDYYHHmm format
> my @log_date = qw($month$day$year$hour$min)

Do you want interpolation here?
[localhost:~] tor% perl -e '$var=12; $var2=24; @r=qw($var$var2); print
"@r\n";'
$var$var2
[localhost:~] tor% 

my $date = $mon00.$mday00.$year.$hour00.$min00;

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: open file into hash

2002-08-14 Thread Tor Hildrum

<[EMAIL PROTECTED]> wrote:

> I have a file called people.data, which contains two colums:
> jose2
> karen8
> jason9
> tracey1
> 
> 
> Can someone tell me what I am doing wrong here:
> =
> #! /usr/bin/perl -w
> 
> open (INPUT, " %people = ;

Not what you want.

foreach () {
($key, $var) = split(/\s+/, $_);
$hash{$key} = $var;
}

Or similar.

Tor


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Understanding Perl better.

2002-02-16 Thread Tor Hildrum

I have 2 questions.

Here is the code:
#!/usr/bin/perl
use warnings;
use strict;

# Merging two files

print ("Write the two files you wan't to merge and \n");
print ("lastly the file to merge them too, seperated by a space.\n");
chop (my $filenames = );

my @names = split(/ /,$filenames); # Get the filenames in an array.

open (FIRSTFILE, "$names[0]") || die ("Couldn't open $names[0]'n");
my @firstfile = ;

open (SECONDFILE, "$names[1]") || die ("Couldn't open $names[1]\n");
my @secondfile = ;

open (WRITEFILE, ">$names[2]") || die ("Couldn't open $names[2] for
writing\n");

# Now to merge the 2 files.

my $counting = 0;

while ($firstfile[$counting] ne "" || $secondfile[$counting] ne "" ) {
print WRITEFILE ($firstfile[$counting]);
print WRITEFILE ($secondfile[$counting]);
$counting++
}

The first thing I don't understand. How come this works even if there are
blank lines in a file, with text after that line? Shouldn't the while-loop
end at blank lines? I have tested it on two files and it works on the whole
file, even though there are blank lines there. Why is this?
PS: The first file is 1 line, the second is 5 lines with line nr 4 beeing a
blank line. Line 5 still shows though.
PS2: I'm aware that my decision to use $counting is dumb, and that I instead
should use the length of the longest array($firstfile or $secondfile), or
isn't that a better solution?

My second question is:
When using use warnings;
I get a long list of messages(warnings) when running this script.
Use of uninitialized value in string ne at ./26.pl line 23, 
line 6.
Use of uninitialized value in print at ./26.pl line 24,  line 6..
I get this pair 6 times in a row, when the script is run.
Is this a problem, or is it normal?

PS: I'm just starting out, so don't flame me if the code is poorly
written(feel free to comment though) :)

Any information is greatly appreciated.

Tor


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Matching

2002-02-27 Thread Tor Hildrum

On 27/2/02 13:11, "Jon Molin" <[EMAIL PROTECTED]> wrote:

> Iain Wallace wrote:
>> 
>> Hi,
>> 
>> I was wondering if any one can help me. Is there any command in perl that
>> will let me match a line only if the next line
>> fufills a certain condition, without doing a double loop over the file?
>> My data is like this
>> 
>> Variable1 number number number
>> Variable1 number number number   --- want this line
>> Variable2 number number number   --- and this
>> Variable2 number number number

I'm pretty new to perl myself, but:

#!/usr/bin/perl -w
use strict;
use warnings;

my $variable1 = "line1 \n line2";
print "$1\n" if $variable1 =~ /(.+)["\n"]\sline.+/;

This is a pretty quick and dirty script that somehow does this.
It doesn't really work that nice, but I guess that would work?
It prints the first line of $variable1, if the second line of $variable one
has line in it.

-- 
T.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Matching

2002-02-27 Thread Tor Hildrum

>> On 27/2/02 13:11, "Jon Molin" <[EMAIL PROTECTED]> wrote:
>> 
>> 
>> Hi,
>> 
>> I was wondering if any one can help me. Is there any command in perl that
>> will let me match a line only if the next line
>> fufills a certain condition, without doing a double loop over the file?
>> My data is like this
>> 
>> Variable1 number number number
>> Variable1 number number number   --- want this line
>> Variable2 number number number   --- and this
>> Variable2 number number number
> 
> I'm pretty new to perl myself, but:
> 
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> 
> my $variable1 = "line1 \n line2";
> print "$1\n" if $variable1 =~ /(.+)["\n"]\sline.+/;


The regex could probably be simplified:
 if $variable1 =~ /[\n]\s/;

Where  is what you would want to be matched for in the second line of
$variable1.

-- 
T.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Dereferencing a referenced hash.

2002-02-28 Thread Tor Hildrum

Is this a bug or a feature?
Or is it just me? :)

!/usr/bin/perl -w
use strict;
use warnings;

my $variable = "variable";
my @array = qw(this is an array);
my %hash = qw(1 this 2 is 3 a 4 hash); ## correct syntax

my $rvariable = \$variable;
my $rhash = \%hash;  ## correct syntax
my $rarray = \@array;


print "\$variable from reference: $$rvariable\n";
print "\@array from reference: @$rarray[0] @$rarray[1] @$rarray[2]
@$rarray[3]\n";
print "\%hash from reference: %$rhash{1} %$rhash{2} %$rhash{3}
%$rhash{4}\n"; ## correct syntax

[localhost:~/Perl/Advanced Perl] tor% ./1.pl
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Global symbol "%rhash" requires explicit package name at ./1.pl line 16.
Execution of ./1.pl aborted due to compilation errors.

I simply can't see that anything is wrong with my syntax.

If I remove -w, use warnings; and use strict;

[localhost:~/Perl/Advanced Perl] tor% ./1.pl
$variable from reference: variable
@array from reference: this is an array
%hash from reference: % % % %

Anyone know why this is happening?

-- 
T.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Sorting a hash table - Advanced;)

2002-02-28 Thread Tor Hildrum

On 27/2/02 17:33, "Steven M. Klass" <[EMAIL PROTECTED]> wrote:

> Hi all,
> 
> ok here is the fundamental code
> 
> print "\n\n**Summary**\n";
> foreach my $key (keys %runset){
>   printf ( "%-20s %-20s\n",$key, $runset{$key});
> }
> 
> Now I want to sort this hash for example
> print "\n\n**Summary**\n";
> foreach my $key (keys %runset){
>   print "Name$runset{foo}"
>   # .. other specific keys
>   printf ( "%-20s %-20s\n",$key, $runset{$key});
> }
> 
> The question is how can I sort the remaining keys that I haven't already
> printed before.
> 
> Basically I want to format this so certain keys get printed in a certain
> order, but there may be some remaining keys that I want printed that I really
> don't care about.  (a "catch-all" if you will)
> 
> Thanks

print "\n\n**Summary**\n";
foreach my $key (keys %runset){
print "Name$runset{foo}"
# .. other specific keys
foreach $key (sort keys %runset) {  ## sort the remaining in ASCII order.
printf ( "%-20s %-20s\n",$key, $runset{$key});
}

Something like that?

-- 
T.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Sorting a hash table - Advanced;)

2002-02-28 Thread Tor Hildrum

 >> Basically I want to format this so certain keys get printed in a certain
>> order, but there may be some remaining keys that I want printed that I really
>> don't care about.  (a "catch-all" if you will)
>> 
>> Thanks
> 
> print "\n\n**Summary**\n";
> foreach my $key (keys %runset){
> print "Name$runset{foo}"
> # .. other specific keys
> foreach $key (sort keys %runset) {  ## sort the remaining in ASCII order.
> printf ( "%-20s %-20s\n",$key, $runset{$key});
> }
> 
> Something like that?

Answering my own post..
After reading this, I realized that you where probably talking about sorting
the specific keys.
Since I'm not really that advanced, it gets bloated fast.

My $counter = "0":
print "\n\n**Summary**\n";
foreach my $key (keys %runset){
   my $array[$counter] = $runset{foo}; ## assign value to array
$counter++;
}## end first foreach.

foreach $key (keys %runset) {
@array[$counter] = $runset{bar};
$counter++;
}## end second foreach


# .. other specific keys
## Now you can sort and print the array.

This probably isn't a good answer, but it might bring forth some of the
guru's :)

-- 
T.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Dereferencing a referenced hash.

2002-02-28 Thread Tor Hildrum

> The trick is to use {$ref} where you would normally put the variable name:

print "${$rhash}{1}\n"; worked like a charm :)
 
> So $array[0] becomes ${$ref}[0] (not @$ref[0] which is a "slice").
> And $hash{key} becomes ${ref}{key}.

It seems somewhat inconsistent to me.
While I can dereference slices from $variables and @arrays this way, I can't
from a %hash? (using $$name, @$name[] and %$name{}).
Maybe it's my lack of understanding hash'es..
 
> Or you can use the little arrow syntax...
> 
> ${$ref}[0] is the same as $ref->[0].
> And ${$ref}{key} is the same as $ref->{key}.

Yes, this looks like the way to go. Much easier and clearer than the
previous syntax.

${$rhash}{1} == $rhash->{1}; ## both are scalar variables, not slices?
 
> In your script you are doing a variation of the first, where you are just
> dropping the curly braces.  In which case it would look like this:
> 
> ${$ref}[0] is the same as $$ref[0] (NOT @$ref[0]).
> ${ref}{key} is the same as $$ref{key}.
> 
> Hope that helps.  Check out the perlreftut manpage, it explains all of this
> pretty well while avoiding all of the nasty details of refs.

Thanks. :)

-- 
T.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How do I pass a hash to a sub, and get to it in the sub?

2002-03-02 Thread Tor Hildrum



> #!/usr/bin/perl
> 
> use strict;
> 
> my %hash = (
>   key1 => 'value 1',
>   key2 => 'value 2',
>   key3 => 'value 3',
> );
> 
> print_hash(\%hash, '=>');
> 
> sub print_hash {
>   my ($hash, $connector) = @_;
> 
>   foreach my $key (sort keys %$hash) {
>   print "$key $connector $$hash{$key}\n";
>   }
> }

I'm new to perl, but isn't this easier to understand:
#!/usr/bin/perl
  
use strict;

my %hash = (
key1 => 'value 1',
key2 => 'value 2',
key3 => 'value 3',
);

print_hash(\%hash);
 
sub print_hash {
my ($hash) = @_;
foreach my $key (sort keys %$hash) {
print "$key => $hash->{$key}\n";
}
}

I took out the $connector and dereferenced with ->.
I am pretty new to Perl, and it took me awhile to understand why you passed
=> to the sub, and what $connector was..
I'm just sayin :)

-- 
T.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: If (/start/ .. /end/) Flip Flop Mechanism

2002-03-02 Thread Tor Hildrum

On 2/3/02 12:06, "Steven M. Klass" <[EMAIL PROTECTED]> wrote:

> Hi all
> 
> I know there is a flip flop option but I'm not sure thats what I need..
> Here is what I want to do - and I have no idea how to do this.
> 
> Basically I have a section of text that I am doing a search and replace
> operation.  The problem is what if the search text doesn't exist - I still
> want to add it.
> 
> So the logic is if it exists in the region replace it, if you can't find it
> add to to it
> 
> if (/start/ .. /end/){
>  s/^foo/bar/;
> 
> }
> now what if foo didn't exist - bar still should be set!
> 
> Any ideas?

While there still is input. While
Match each line in an if else structure if ($_ =~ regex)
Then do something(replace).
Then you can use elsif to check if line is empty something like $_ == "\n"??

open (FILE, "filename");
While () {
if ($_ =~ /^tor/i) { # starts with tor
 # Replace the line
} # end if
elsif ($_ == "\n") { # newline for empty lines
# Replace the "line"
} # end elsif
Else {
# Do nothing? 
} # end else
} # end while.

That is at least one way.
I'm sure there are other and better ways to do this.

-- 
T.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Problems with regex only matching first match on a line.

2002-03-05 Thread Tor Hildrum

#!/usr/bin/perl -w
use strict;
use warnings;

print "What file do you want to open?\n";
chomp(my $openfile = );
print "What file do you want to write to?\n";
chomp(my $outfile = );
print "What do you want to replace in the first file?\n";
chomp(my $pattern = );
print "What do you want to replace it with?\n";
chomp(my $replace = );

open (INFILE, "$openfile") or die "Can't open $openfile: $!\n";
open (OUTFILE, ">$outfile") or die "Can't open $outfile: $!\n";

while () {
if ($_ =~ /$pattern/i) {
s/$pattern/$replace/;
print OUTFILE $_; }
else {
print OUTFILE $_; }
}

The script is pretty self-explanatory.
The problem is that it is only replacing the first match on each line.
Is there a way to do this with regex?
I think I could do something like: while($_ =~ /$pattern/i) {replace the
lines}. But, I was wondering if this could be handled within my if-else
structure?

-- 
T.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Might be OT. Making a webpage.

2002-03-21 Thread Tor Hildrum

I just recently got a project to put up a webpage that had a registration
form, saved all registrations and emailed out information to the people who
registered and made reports on who had registered and emailed those reports.
I had a lot of fun while doing it(and learned a lot), so now I want to make
my own Perl/CGI webpage. But, I don't really see any options in CGI.pm to
give the site the kind of design I want. Is there some place I could look
for information about the design options CGI.pm provides? I tried using
perldoc, but couldn't find any relevant information there. Is it advisable
to use CGI.pm, or should I just make a HTML-page and imbed my scripts into
that?

I have heard writing HTML-code in *.cgi-scripts is considered a no-no, is
there any validity to this?

Sorry for going slightly off-topic, but this list doesn't have to be
troubleshooting-only. And even though there are CGI-lists, I'd rather prefer
to ask on this one(feel honoured :) ).

-- 
Tor Hildrum.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: how to sort, in to out

2002-03-21 Thread Tor Hildrum

On 21/3/02 15:04, "David Gray" <[EMAIL PROTECTED]> wrote:

>> I am trying to figure out an easy way to sort out a array of numbers:
>> 2 20 38 56 75 93 -17 -35 -53 -72 -90
>> Into the following:
>> -90 -72 -53 -35 -17 2 20 38 56 75 93
>> I have done the following:
>>   @x_step  = grep { ! $x_step_t{ $_ }  ++ } @x_step_t;
>>   @x_step = sort {$a == $b} @x_step;
> 
> You're really close:
> 
> @x_step = reverse sort {$a<=>$b} @x_step;
> 
> -dave

I thought of that right away too. But, wouldn't it produce the wrong array?
-90 -72 -53 -35 -17 93 75 56 38 20 2?

-- 
T.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: creating a hash

2002-03-21 Thread Tor Hildrum

On 21/3/02 15:49, "Trice Dennis D" <[EMAIL PROTECTED]> wrote:

> I'm trying to create a hash of the /etc/group file.  I need the key to be
> the group name and just the members of the group to be the key value.
> 
> Has anyone done this before?
> 

I'm guessing you know how to grab a normal hash from such a file using a
while-loop? You will need to use an array as the hash-value for each given
key(key=group, hash-value=array of users).
man perldsc explains that.
I think :)

-- 
T.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Might be OT. Making a webpage.

2002-03-24 Thread Tor Hildrum

On 21/3/02 22:23, "Michael Kelly" <[EMAIL PROTECTED]> wrote:
> What do you mean? CGI.pm seems to have a function for generating just about
> every HTML that ever did, does, or will exist. Maybe I'm misunderstanding
> what you mean by "Perl/CGI webpage"...

I'm pretty sure it does, I'm just having problems finding information about
what "you get" when using CGI.pm. I recently found out I could read the
CGI.pm, and it is well documented, so that helps a lot.

Here is an example of the problem I am having:
I've made this mail.form, it is simply a form that you can use to send me an
email. I'm using CGI.pm. I can't figure out how to change the
background-color on the page. This is very trivial, and I'm sure I will find
it explained once I look in CGI.pm. But, another problem is the size of my
textfields. I have a textfield for the message, and I want that to be over
multiple lines, not just one.

Here is my code:
print p("Your message: ", textfield(-NAME => "message", -VALUE => "", -SIZE
=> $ 250)), hr;

This gives me a long inputfield, but only over 1 line. This is ugly, and bad
UI, so I want more lines. I couldn't figure out how to do this by reading
CGI.pm.
 
>> I have heard writing HTML-code in *.cgi-scripts is considered a no-no, is
>> there any validity to this?
> 
> No, it's not. Some people think it's prettier to use CGI.pm, others (like
> me) prefer total control of their HTML output and just use here-docs.

That is nice to know, as sometimes it easier to use plain HTML-tags, when I
can't figure out how to do something with CGI.pm.

One last question, some more code:
my $email = param("email"); # user inputs his email-address.
...
Later in the script:
chomp($name, $email);
$email = ($email =~ s/@/\\@/); # escape the @

I inserted these, but I'm not really sure they are needed.

I get the params normally by:
print p("Your name: ", textfield("name", "name"));
print p("Your email-address: ", textfield("email",
"whatever\@whatever.com"));

Could I leave those 2 steps out?
 
Again, if this is OT I apologize.
-- 
T.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]