【Newbie】var eq range of ##?【PERL】
1
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?
2
Name:
Anonymous
2009-08-11 3:15
use a loop
3
Name:
Anonymous
2009-08-11 3:22
>>2
Thanks a lot! It worked.
4
Name:
Anonymous
2009-08-11 3:36
IHBT :(
5
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.
6
Name:
Anonymous
2009-08-11 16:39
7
Name:
Anonymous
2009-08-11 22:05
>>6
Can't "last" outside a loop block at >>5 line 1.
So close ;(
8
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!?!?!
9
Name:
Anonymous
2009-08-11 23:32
You'll note that in that tiny line of C code he made 3 obvious errors.
10
Name:
Anonymous
2009-08-11 23:35
>>9
Is one of those breathing?
11
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".
12
Name:
Anonymous
2009-08-12 15:19
you've obviously never programmed before
14
Name:
D
2010-12-06 4:10
The D Programming Language
15
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
16
Name:
Anonymous
2010-12-06 7:19
my $j = [|] 5..10;
for 1..20 { .say when $j }
17
Name:
Anonymous
2010-12-06 7:59
>>16
Why do it in Ruby if you can do it in Perl.
REGEXPS GALORE
18
Name:
Anonymous
2010-12-24 0:50
19
Name:
Anonymous
2011-02-04 20:01