Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: asterisk pattern

by Corion (Pope)
on Oct 27, 2011 at 11:35 UTC ( #934120=note: print w/replies, xml ) Need Help??

in reply to asterisk pattern

The following works for me:

$b=this_code_is_from_perlmonks_org; for my $a(some_program_was_written_for_perlmonks_org=~/[st]/g){ print $a,sprintf '%4s','*'x(2+($a cmp $b)), qq(\n); $b=$a }

Update: I didn't get the requirement of outputting different depths, so here is an improved variation on the same theme:

$level=12; my $i=12; my $l=$level-12; $_ = #$; this_program_source_was_written_for_the_site_perlmonks_org. please_do_not_give_this_code_to_your_teacher_without_understanding. We_value_learning_but_the_work_has_to_be_done_by_yourself. kthxbai; $b=a_program_written_by_Corion; for $a(($_.reverse)=~/[sx]/g){ $d=($a cmp $b)||$d; $l+=$d; $b=$a; print sprintf '%'.$i.'s', '*'x$l, qq(\n) unless $l<0 }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://934120]
[LanX]: could
[LanX]: $#array gives the length
[LanX]: no sorry ...
[sierpinski]: so that would just be deferencing it...
[LanX]: the last index!
[LanX]: yes
[sierpinski]: yeah I guess $list is a reference.. yeah
[sierpinski]: why is it the last index and not the first? because the length of the array becomes the index?
[sierpinski]: thanks LanX that helps
[haukex]: the first index is always 0 - $#array gives you the last index in @array

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2017-12-13 16:00 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (369 votes). Check out past polls.