Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

【Newbie】var eq range of ##?【PERL】

Name: Anonymous 2009-08-11 3:13

/prog/ I need help.

I have two variables $first and $last. Both of these are numbers, for example 5 and 10.

I need a script to print a line whenever variable $line (also a number) is equal to any number in the range $first to $last

What's the best way to go about it? Is there some neat Perl trick?

Name: Anonymous 2009-08-11 3:15

use a loop

Name: Anonymous 2009-08-11 3:22

>>2
Thanks a lot! It worked.

Name: Anonymous 2009-08-11 3:36

IHBT :(

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !frozEn/KIg 2009-08-11 11:52

What is so hard? if(line<last && line>first){printf(linetext);}



_____________________________________________
http://xs135.xs.to/xs135/09042/av922.jpg
Velox Et Astrum gamedev forum: http://etastrum.phpbb3now.com
The philosopher is Nature's pilot. And there you have our difference: to be in hell is to drift: to be in heaven is to steer.

Name: Anonymous 2009-08-11 16:39

>>5
NOT VALID PERL CODE

Name: Anonymous 2009-08-11 22:05

>>6
Can't "last" outside a loop block at >>5 line 1.
So close ;(

Name: Anonymous 2009-08-11 23:30

In the brief 30 seconds I have spent staring at this board, it is self-evident that the FROOOOOOOZEN VOOOOOOOOOOOOOOIDDDDDDDD is an ENTERPRISE CLASS programmer.

Balls are touching!?!?!

Name: Anonymous 2009-08-11 23:32

You'll note that in that tiny line of C code he made 3 obvious errors.

Name: Anonymous 2009-08-11 23:35

>>9
Is one of those breathing?

Name: Anonymous 2009-08-11 23:46

>>9
That's what happens when you don't teach your children the meaning of "first" and "last".

Name: Anonymous 2009-08-12 15:19

you've obviously never programmed before

Name: D 2010-12-06 4:10

The D Programming Language

Name: Anonymous 2010-12-06 5:11

Behold! A Perl way of solving your problem!
$ perl -e 'foreach my $i (1..20) { print "$i ", grep(/^$i$/, (5..10)) ? "yes" : "no", "\n"; }'
1 no
2 no
3 no
4 no
5 yes
6 yes
7 yes
8 yes
9 yes
10 yes
11 no
12 no
13 no
14 no
15 no
16 no
17 no
18 no
19 no
20 no

Name: Anonymous 2010-12-06 7:19

my $j = [|] 5..10;
for 1..20 { .say when $j }

Name: Anonymous 2010-12-06 7:59

>>16
Why do it in Ruby if you can do it in Perl.
REGEXPS GALORE

Name: Anonymous 2010-12-24 0:50

Name: Anonymous 2011-02-04 20:01


Don't change these.
Name: Email:
Entire Thread Thread List