Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Limit loop

by htmanning (Friar)
on Aug 30, 2022 at 23:02 UTC ( #11146523=note: print w/replies, xml ) Need Help??

in reply to Re: Limit loop
in thread Limit loop

Thanks. This is an example of the $favorites field:
Adam Knowles||||||11977~~~Alex Burleson| +|||||27627~~~Billy||| +om/?ID=18836|||18836~~~Billy||||||18836 +~~~Christopher Duarte||||||14713~~~Dave + Martin||||||5590~~~Drew Rubado|||https: +//|||26867~~~Emily Hanson||| +m/?ID=6782|||6782~~~James Gehrke||||||78 +34~~~Jeff Banta||||||11446~~~Jeffrey P +Sandoval||||||14637~~~Jesse Bollinger|| +||||8034~~~Jonathan Walker|||https://www|||4811~~~Jordan Hall||| +549|||12549~~~Joseph Dodds||||||26211~~ +~Mark Tappan||||||5370~~~Mary Christine +Hammill-Perkins||||||15901~~~Mary E. Bo +esch||||||20326~~~Matthew Smith|||https +://|||26752~~~Matthew Tuggle||||||13170~~~Moises Cariaso||| +397|||27397~~~Nicole Masciola||||||2723 +0~~~Paul Zenns||||||8396~~~Paul Zenns||| +|||8396~~~Phillip Scott||||||5015~~~Ross Martin||| +|||27192~~~Sam Lavine||||||26277~~~Step +hen Beatty Jr||||||10557~~~TODD A PARTI +N||||||21876~~~
Unfortunately I'm just a hack and I didn't write this. It looks like the last number gets stuffed into the $favnums var and that is stuffed into a cookie. I think it's too long for the cookie to handle if there are more than 25 favorites or so which is why I'm trying to chop it down. I'm sure I'm doing something wrong but none of these suggestions have led me to the answer. I've tried setting a counter to zero and adding one to the counter at the end of the loop and then telling it to stop if it reaches 25, but I must be doing something wrong because it doesn't work. I'll keep trying. Thank you for all who have attempted to help.

Replies are listed 'Best First'.
Re^3: Limit loop
by Marshall (Canon) on Aug 31, 2022 at 05:53 UTC
    now that you show the actual data, I would just get the nums from the end of the lines via match global, thusly:
    use strict; use warnings; my $str = 'Adam Knowles||||||11977~~~Ale +x Burleson||||||27627~~~Billy|||https:/ +/|||18836~~~Billy||| +836|||18836~~~Christopher Duarte||||||1 +4713~~~Dave Martin||||||5590~~~Drew Ruba +do||||||26867~~~Emily Hanson|||https://|||6782~~~James Gehrke||| +D=7834|||7834~~~Jeff Banta||||||11446~~ +~Jeffrey P Sandoval||||||14637~~~Jesse +Bollinger||||||8034~~~Jonathan Walker||| +|||4811~~~Jordan Hall||||||12549~~~Joseph Dodds||| +1|||26211~~~Mark Tappan||||||5370~~~Mary + Christine Hammill-Perkins||||||15901~~ +~Mary E. Boesch||||||20326~~~Matthew Sm +ith||||||26752~~~Matthew Tuggle|||https +://|||13170~~~Moises Cariaso||||||27397~~~Nicole Masciola||| +7230|||27230~~~Paul Zenns||||||8396~~~Pa +ul Zenns||||||8396~~~Phillip Scott|||htt +ps://|||5015~~~Ross Martin||| +m/?ID=27192|||27192~~~Sam Lavine||||||2 +6277~~~Stephen Beatty Jr||||||10557~~~T +ODD A PARTIN||||||21876~~~'; my @favnums = $str =~ /\|\|\|(\d+)~/g; $#favnums = 24 if ($#favnums >24); #maximum of 25 fav's my $favnumstr = join ",",@favnums; print $favnumstr; 11977,27627,18836,18836,14713,5590,26867,6782,7834,11446,14637,8034,48 +11,12549,26211,5370,15901,20326,26752,13170,27397,27230,8396,8396,501 +5
      Thank you! This works.
Re^3: Limit loop
by hippo (Bishop) on Aug 31, 2022 at 08:30 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146523]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2023-05-28 15:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found