Ask a Question related to PERL Beginners, Design and Development.
-
DBSMITH@OhioHealth.com #1
case and functions
Yo.....
I read in Learning Perl that there are no such constructs like a case statement. Is there
something similar or did I misread this? Also what about functions and
function calls, do these exits or does the subroutines replace these?
thanks
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
DBSMITH@OhioHealth.com Guest
-
#23026 [Com]: Make Zend case-sensitive (classes, functions, remove case-insensitive)
ID: 23026 Comment by: nvivo at mandic dot com dot br Reported By: mfischer@php.net Status: Open Bug Type: ... -
Case conversions
On Friday, August 15, 2003, at 04:20 PM, Scott Taylor wrote: Maybe something like: s/^(\w+), ?(\w+)$/ucfirst(lc $2) . ' ' . ucfirst(lc $1)/e... -
using case with classes
Ok, this did not work like I expected (because I know too little about Ruby): def test( obj ) case obj.class when Array then puts "Array" when... -
#10743 [Com]: class functions & PHP core functions inconsistently clash ;)
ID: 10743 Comment by: destes at ix dot netcom dot com Reported By: jjones at net-conex dot com Status: Open... -
Case Checks
When I couldn't sleep this morning, this came across my head: class Check def initialize(sym, args) @args=args instance_eval "def ===(obj);... -
Anthony Esposito #2
RE: case and functions
There is no 'case' statement in Perl but it is easy to mimic such a construct.
Tony Esposito
Oracle Developer, Enterprise Business Intelligence
XO Communications
Plano, TX* 75074
Work Phone: 972-516-5344
Work Cell: 972-670-6144
Email: [email]anthony.esposito@xo.com[/email]*
-----Original Message-----
From: [email]DBSMITH@OhioHealth.com[/email] [mailto:DBSMITH@OhioHealth.com]
Sent: Tuesday, January 06, 2004 4:08 PM
To: [email]beginners@perl.org[/email]
Subject: case and functions
Yo.....
I read in Learning Perl that there are no such constructs like a case statement. Is there
something similar or did I misread this? Also what about functions and
function calls, do these exits or does the subroutines replace these?
thanks
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
Anthony Esposito Guest
-
Dan Muey #3
RE: case and functions
> Yo.....
What's up dog? :)
Yes, there is.>
> I read in Learning Perl that there are no such constructs
> like a case statement. Is there
Do you mean:
if(this) { do this }
elsif(that) { do that }
else { do the other }
Functions and subroutines are *basically* the same thing.> something similar or did I misread this? Also what about
> functions and
> function calls, do these exits or does the subroutines replace these?
Perldoc perlsub I believe addresses this.
HTH
DMuey
>
> thanksDan Muey Guest
-
Jenda Krynicky #4
Re: case and functions
From: [email]DBSMITH@OhioHealth.com[/email]
Ask the FAQ, run> I read in Learning Perl that there are no such constructs like a case
> statement. Is there something similar or did I misread this?
perldoc -q "case statement"
Subroutines are both what some languages call procedures and> Also
> what about functions and function calls, do these exits or does the
> subroutines replace these?
functions.
Jenda
===== [email]Jenda@Krynicky.cz[/email] === [url]http://Jenda.Krynicky.cz[/url] =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
Jenda Krynicky Guest
-
Chuck Fox #5
Re: case and functions
[email]Jenda@Krynicky.cz[/email] wrote:
Have you checked into Switch.pm ? It provides a switch/case construct>From: [email]DBSMITH@OhioHealth.com[/email]
>
>>>>I read in Learning Perl that there are no such constructs like a case
>>statement. Is there something similar or did I misread this?
>>
>>
>Ask the FAQ, run
>
> perldoc -q "case statement"
>
>
>>>>Also
>>what about functions and function calls, do these exits or does the
>>subroutines replace these?
>>
>>
>Subroutines are both what some languages call procedures and
>functions.
>
>Jenda
>===== [email]Jenda@Krynicky.cz[/email] === [url]http://Jenda.Krynicky.cz[/url] =====
>When it comes to wine, women and song, wizards are allowed
>to get drunk and croon as much as they like.
> -- Terry Pratchett in Sourcery
>
>
>
similar to a C switch.
HTH,
Chuck
Chuck Fox Guest
-
DBSMITH@OhioHealth.com #6
Re: case and functions
People of the Perl,
thanks for the info....I am familiar with perls subroutines so I will use
these and this name instead of functions. Also, my intention was to avoid
the if , then ,elif, then constructs, mentioned by Dan, for certain
situations which is why I asked about cases so I will read the perldoc.
thanks
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
"Jenda Krynicky" <Jenda@Krynicky.cz>
01/06/2004 05:18 PM
To: [email]beginners@perl.org[/email]
cc:
Subject: Re: case and functions
From: [email]DBSMITH@OhioHealth.com[/email]Ask the FAQ, run> I read in Learning Perl that there are no such constructs like a case
> statement. Is there something similar or did I misread this?
perldoc -q "case statement"
Subroutines are both what some languages call procedures and> Also
> what about functions and function calls, do these exits or does the
> subroutines replace these?
functions.
Jenda
===== [email]Jenda@Krynicky.cz[/email] === [url]http://Jenda.Krynicky.cz[/url] =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
DBSMITH@OhioHealth.com Guest
-
Randal L. Schwartz #7
Re: case and functions
>>>>> "DBSMITH" == DBSMITH <DBSMITH@OhioHealth.com> writes:
DBSMITH> Also, my intention was to avoid the if , then ,elif, then
DBSMITH> constructs, mentioned by Dan, for certain situations
What is the source of your fear? Sounds like a phobia to me.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal L. Schwartz Guest
-
R. Joseph Newton #8
Re: case and functions
[email]DBSMITH@OhioHealth.com[/email] wrote:
Don't give up quite so quickly. At least in Perl 5.8, there is abuilt-in> People of the Perl,
>
> thanks for the info....I am familiar with perls subroutines so I will use
> these and this name instead of functions. Also, my intention was to avoid
> the if , then ,elif, then constructs, mentioned by Dan, for certain
> situations which is why I asked about cases so I will read the perldoc.
>
> thanks
>
> Derek B. Smith
Switch module, as Chuck Fox has also pointed out.
Joseph
R. Joseph Newton Guest
-
William Ampeh #9
Re: case and functions
You can do something like this:
my $flip = "something";
SWITCH: {
( $flip =~ /^0$/ || $flip =~ /^1$/ || $flip =~ /^2$/ ) && do {
$local_pref = "FL"; last SWITCH; };
( $flip =~ /^3$/ || $flip =~ /^4$/ || $flip =~ /^5$/ ) && do {
$local_pref = "FU"; last SWITCH; };
( $flip =~ /^6$/ || $flip =~ /^7$/ ) && do {
$local_pref = "FA"; last SWITCH; };
( $flip =~ /^8$/ || $flip =~ /^9$/ ) && do {
$local_pref = "FS"; last SWITCH; };
} # end switch
__________________
William Ampeh (x3939)
Federal Reserve Board
William Ampeh Guest
-
binhqnguyen@bellsouth.net #10
Array Manipulations
Hello Everyone,
I am a Perl newbie trying to learn as much Perl as I can. I am trying to
combine specific array elements into one single array element so that I can
write
to an Excel cell, where all the data will fit.
For instance I have,
array[0] = "F1: blue";
array[1] = "F2: green";
array[2] = "F3: red";
array[3] = "F1: purple";
array[4] = "F2: brown";
array[4] = "F1: red";
array[5] = "F2: pink";
array[6] = "F3: blue";
array[7] = "F4: white";
With the above information, I want to put all the F's in order before it
starts over at 1 again. For instance, I want to store array[0], array[1],
and array[2] into a specific array element and then store array[3], array[4]
into another specific array element, then I start over again with array[5].
Each time I encounter an F1, I will store all the particular elements into
one single array element. Is this possible?
Thanks for your time.
binhqnguyen@bellsouth.net Guest
-
Drieux #11
Re: case and functions
On Jan 6, 2004, at 2:08 PM, [email]DBSMITH@OhioHealth.com[/email] wrote:
what Up.> Yo.....
As folks have already pointed to both> I read in Learning Perl that there are no such constructs
> like a case statement. Is there something similar or did I misread
> this?
the classic perlfaq, and implied that
one should consult
perldoc Switch
which if you are not on perl5.8 can be
downloaded from the CPAN from
<http://search.cpan.org/~dconway/Switch-2.09/Switch.pm>
[..]> Also what about functions and function calls,
> do these exits or does the subroutines replace these?
This of course brings us to the more interesting
side of the swtich/case statement problem - namely
what are you trying to do with them, and have you
thought about the classic 'dispatching table' type
of solution - say something like
my %process = (
start => \&do_start,
stop => \&do_stop,
test => \&do_test
);
if ( defined( $process{$ARGV[0]}))
{
$process{$ARGV[0]}(@ARGV);
} else {
print "issued invalid command: $ARGV[0]\n";
}
sub do_start { ... }
sub do_stop { ... }
sub do_test { ... }
you will notice that this is similar to the classic
init script most folks have seen as say
#!/bin/sh
case "$1" in
"start") do_start ;;
"stop") do_stop ;;
"test") do_test ;;
*) echo "i do not know how to to $1" ;;
esac
So it's sorta a case of what exactly were you trying
to do with the case like statement???
ciao
drieux
---
Drieux Guest
-
John W. Krahn #12
Re: Array Manipulations
[email]binhqnguyen@bellsouth.net[/email] wrote:
Hello,>
> Hello Everyone,
Is this what you want?> I am a Perl newbie trying to learn as much Perl as I can. I am trying to
> combine specific array elements into one single array element so that I can
> write
> to an Excel cell, where all the data will fit.
>
> For instance I have,
>
> array[0] = "F1: blue";
> array[1] = "F2: green";
> array[2] = "F3: red";
> array[3] = "F1: purple";
> array[4] = "F2: brown";
> array[4] = "F1: red";
> array[5] = "F2: pink";
> array[6] = "F3: blue";
> array[7] = "F4: white";
>
> With the above information, I want to put all the F's in order before it
> starts over at 1 again. For instance, I want to store array[0], array[1],
> and array[2] into a specific array element and then store array[3], array[4]
> into another specific array element, then I start over again with array[5].
> Each time I encounter an F1, I will store all the particular elements into
> one single array element. Is this possible?
$ perl -le'
use Data::Dumper;
@array = ( "F1: blue",
"F2: green",
"F3: red",
"F1: purple",
"F2: brown",
"F1: red",
"F2: pink",
"F3: blue",
"F4: white" );
my ( $index, @new ) = -1;
push @{ $new[ /^F1:/ ? ++$index : $index ] }, $_ for @array;
print Dumper \@new;
'
$VAR1 = [
[
'F1: blue',
'F2: green',
'F3: red'
],
[
'F1: purple',
'F2: brown'
],
[
'F1: red',
'F2: pink',
'F3: blue',
'F4: white'
]
];
John
--
use Perl;
program
fulfillment
John W. Krahn Guest



Reply With Quote

