RE: detecting a hash of hashes

2001-12-06 Thread Sidharth Malhotra

Try the ref() function.
  if (ref($hash{$data}) eq 'HASH') {}

Hth.  Sid.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf
Of Pete Emerson
Sent: Thursday, December 06, 2001 9:03 AM
To: [EMAIL PROTECTED]
Subject: detecting a hash of hashes


Here is an example of what I'm doing to detect whether I've got a scalar
value in my hash or a hash of hashes:

#!/usr/bin/perl -w

use strict;
my %hash;
$hash{name}='Pete';
$hash{color}{favorite}='Blue';
$hash{color}{car}='Silver';
$hash{color}{house}='White';
foreach my $data (keys %hash) {
  if ($hash{$data}!~/HASH\(\S+\)/) {
print "\$hash{$data} --> $hash{$data}\n";
  } else {
foreach my $second (keys %{$hash{$data}}) {
   print "\$hash{$data}{$second} --> $second\n";
}
  }
}

Is there a better way to do this that doesn't use a regex to detect the
existence of a hash vs. a scalar value?
Pete


-- 
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 to remove control M's

2001-12-05 Thread Sidharth Malhotra

Most unix systems have a program called dos2unix that does the same
thing.
% man dos2unix
% dos2unix sourcefile targetfile

Hth.  Sid.

-Original Message-
From: Chris Spurgeon [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, December 05, 2001 5:41 PM
To: 'Booher Timothy B 1stLt AFRL/MNAC'; [EMAIL PROTECTED]
Subject: RE: perl script to remove control M's


perl -i.bak -npe 's/\r\n/\n/g' 

where  is the filename you want to clean.
A backup copy of your original file will be created in the same
directory with a ".bak" extension.


Chris Spurgeon
Senior Design Technologist
[EMAIL PROTECTED]

ELECTRONIC INK
One South Broad Street
19th Floor
Philadelphia, PA 19107
www.electronicink.com

t 215.922.3800 x(233)
f 215.922.3880


-Original Message-
From: Booher Timothy B 1stLt AFRL/MNAC
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 05, 2001 5:32 PM
To: [EMAIL PROTECTED]
Subject: perl script to remove control M's



I have what seems to be a persistent problem with all files that I
import from dos into emacs. I have those control M's all over the place.

Does anyone know of a perl script to 'clean' these files?

Thanks so much,

tim

Timothy B Booher, Lt USAF, AFRL/MNAC
101 West Eglin Blvd, Suite 339 
Eglin AFB FL 32542-6810 
Phone: 850-882-8302 Ext. 3360 (DSN 872-)
FAX: 850-882-2201

This e-mail is intended solely for the above-mentioned recipient and it
may contain confidential or privileged information.  If you have
received it in error, please notify us immediately and delete the
e-mail.  You must not copy, distribute, disclose or take any action in
reliance on it.  In addition, the contents of an attachment to this
e-mail may contain software viruses which could damage your own computer
system.  While Electronic Ink, Inc. has taken every reasonable
precaution to minimize this risk, we cannot accept liability for any
damage which you sustain as a result of software viruses.  You should
perform your own virus checks before opening the attachment.

-- 
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]




floating point arithmetic

2001-11-28 Thread Sidharth Malhotra

I encountered a problem with floating point arithmetic that I'm afraid
may be causing greater calculation errors in my program.  The program
I'm writing calculates numerical solutions for ordinary differential
equations (http://sid.cwru.edu/perl/euler.pl).   What's happening is
that floating point storage is not rounding off properly and down the
line 
2.4 + 0.025 = 2.424999 instead of 2.425.  You can easily spot
the error in this short script:
 
my $num = 1;
my $add = 0.025;
while ($num < 4) {
$num += $add;
print $count++ . "  $num\n";
}
 
The resulting error in my particular differential equation is 2/10^15
which is fine exept the the error gets compounded over a few hundred
iterations.  Does anyone have any suggestions for how to improve upon
this?  I do understand that there are accuracy limitations with floating
pt. nums.
 
Thanks,
 
Sid.
-----
Sidharth Malhotra
[EMAIL PROTECTED]
 



RE: a beginners challenge

2001-11-28 Thread Sidharth Malhotra

He didn't specify perl.  So I guess this works.

-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, November 28, 2001 1:37 PM
To: 'Zysman, Roiy'; '[EMAIL PROTECTED]'
Subject: RE: a beginners challenge


> -Original Message-
> From: Zysman, Roiy [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, November 28, 2001 1:19 PM
> To: '[EMAIL PROTECTED]'
> Subject: a beginners challenge
>
>
>
> > Hi All,
> > Why not make a little challenge ..
> > Lets see who can write the most lean ,mean , elegant ,
> powerful, poetic
> > (but most important)  _Shortest_, script that cleans from a
> directory
> > files that are at least 3 days old.

$ find /dir -mtime +3 -exec rm {} \;

> > Good luck all,

Gee, thanks.

> > You're welcome to pick who you think is the winner.

OK, I pick myself. What do I win?

> > Roiy

-- 
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: Simple question

2001-11-25 Thread Sidharth Malhotra

It will only match anything beginning with "daniel": "daniel",
"daniella", "danielson", "daniel smith"  
If you specifically want to match only "daniel" try:
/^$user$/

Hth.  Sid.

-Original Message-
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, November 25, 2001 11:55 PM
To: [EMAIL PROTECTED]
Subject: Simple question


Hey all,

Just a simple question could some one give me a clue as to what the
folling regex will match...

$user = "daniel";

if ( $test =~ /^$user/ ) {
   print "Hello world!\n";
}

Will it match only daniel or will it match dan || danni and so on?

Cheers,

Dan

-- 
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: What is "bubble sort"?

2001-11-15 Thread Sidharth Malhotra

While were on this, I'm taking an intro to Data Structures class and
were learning all about the different sorting methods ... Insertsort,
mergesort etc.  What kind of sorting method perl's sort() use?

Sid.

-Original Message-
From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, November 15, 2001 7:39 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: What is "bubble sort"?


(Cross-posted to the Perl Beginners List)

On Nov 15, Tommy Butler said:

>What's a "bubble sort" ?  I believe I heard the term used on this list 
>a while back.  I have some kind of idea of what it is, and how it would

>be implemented, but I'd like to find out for sure.  Could someone tell 
>me what it is, under what circumstances is it beneficial, what are the 
>benefits, how it is implemented, and how does it work?

Bubble sort is a naive sorting algorithm.  It's called "bubble" sort
because the larger elements "rise" to the "top" of the list, like a
bubble in water.  You compare two adjacent items in a list -- if the
left is larger than the right, you swap them; if not, do nothing.  Then,
you move the bubble up one element.  You continue this process until you
don't need to swap any more.

Here is a simple demonstration of the algorithm:

  LIST = 5  7  3  2  8  4
[5  7] 3  2  8  4
 5 [7  3] 2  8  4
 5  3 [7  2] 8  4
 5  3  2 [7  8] 4
 5  3  2  7 [8  4]
 5  3  2  7  4  8

That was just ONE pass.  In a list of N elements, you will need at most
N passes (and that is when the list is in REVERSED order).  If the list
is already sorted, you only need ONE pass.

Here is a Perl implementation of bubble sort.  This sorting technique is
not very useful anymore, since things like heaps are around.  Still, it
is one of the first sorting techniques computer science students learn.

  sub bubble {
my $a = shift;
my $swap = 1;  # did we have to swap?

while ($swap) {
  $swap = 0;  # assume we don't have to swap

  for $i (0 .. @$a - 2) {
if ($a->[$i] > $a->[$i+1]) {# if LEFT > RIGHT
  @$a[$i,$i+1] = @$a[$i+1,$i];  # swap them
  $swap = 1;# we had a swap
}
  }
}
  }

And that's it.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]
http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/
http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002
**


-- 
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: what is @$data

2001-11-04 Thread Sidharth Malhotra

$data is a reference to an array (kind of like a c pointer):

$data = \@somearray;   # or
$data = [1, 2, 4, 7];  # there are many other ways to create an array
ref

When you say @$data, you dereference $data into array context because
shift requires arrays to work with:

my ($type) = shift @$data;

Shifts the array that $data points to.

Hth.  Sid.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, November 04, 2001 5:33 AM
To: [EMAIL PROTECTED]
Subject: what is @$data


i have come a cross a array-scalar combo that i cant figure out, maybe
someone can help. the line off code is:
my ($type) = shift @$data;

does the $ in @$data mean to place $type after @data as opposed to
before in the new @data?
-- 
  - josh
N8MSO

20A8 2FC6 9099 D215 78F4 D005 B9F3 21C4 300C C25E~. .~   Tk Open
Systems
=}ooO--U--Ooo---
-{=
   - [EMAIL PROTECTED] - tel: +972.58.520.636, http://www.tkos.co.il


-- 
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: Is ggoing to mod_perl easy?

2001-10-30 Thread Sidharth Malhotra

Porting to mod_perl is not exceptionally difficult.  Once you have your
Apache/mp server up you can still run your scripts as regular cgi, and
"port" them to mod_perl one by one.  When you "port" a script to
mod_perl, you simply need to put it into a directory where scripts are
being compiled with mp as from the directory (/cgi-bin) where they are
being executed as cgi.  You only need to take caution that your scripts
run normally under mp.

Here you have the advantage that you are already using strict.  Having
done this from the beginnning will make your life several times easier
as you port.  Read http://perl.apache.org/guide/porting.html for more.

Hth.

Sid.

-Original Message-
From: Etienne Marcotte [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, October 30, 2001 8:20 AM
To: [EMAIL PROTECTED]
Subject: Is ggoing to mod_perl easy?


I am now doing my website not using mod_perl. I am however using strict
everywhere.

If I see that the performances aren't satisfying (on a mySQL database),
would it be hard to go to mod_perl? Or it's really better to develop
right from the start in mod_perl?

I have an hard time fully understanding how mod_perl works so that's why
I'm asking:-)

Etienne


-- 
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: system calls

2001-09-21 Thread Sidharth Malhotra

I did this in one of my programs and it seemed to work just fine:

system("$command &");

Which, I believe, runs your command in the background and lets you return to
your program. (Please correct me if I am wrong).  This will only work on
*nix systems.

Sid.

-Original Message-
From: Jonathan Howe [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 21, 2001 11:26 AM
To: [EMAIL PROTECTED]
Subject: system calls


Is it possible when making a call to the system, using the system command
our back ticks to have a script exit/finish
with out hanging around for a return from the process handed to the system.

cheers all


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




RE: HOW TO "HIDE" DOS CONSOLE : from apache webserver (using win98)

2001-09-06 Thread Sidharth Malhotra

yes, you can run it as a service:

apache -k install -n Apache

or simply run it in the background

apache -k start -n Apache

I think these should work.

Sid.

-Original Message-
From: Danny Reyna [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 06, 2001 9:58 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: HOW TO "HIDE" DOS CONSOLE : from apache webserver (using win98)


does anyone know how to hide the dos console that
pops up and doesnt leave when you run the apache
webserver..

any help would be appreciated!
Thanks 
Danny

__
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.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]