Keep yer notes

I was cleaning up some papers out of a notes binder this AM and blundered across something I scribbled down during a YACEU, (not sure if it ws 08 or 09). On closer examination it was a number of notes taken during one of the lighting talk session.

Nothing that I would want 5 years later the only interesting bits where some of those magic/secret/sacred code one-lines that somebody always presentes during one the the lightning talks.

I rarely use them myself except for the good old spaceship operator or

<=>

Useful when you want to sort this @(-1,23,5,-6,0) you want this @(-6,-1,0,5,23 ) and get this @(-1 -6 0 23 5)*

Used normally like this


my @arry = (-1,23,5,-6,0);

my @sorted = sort({$a<=>$b}) @arry;

Well there where a number of other obscure which I am sure have been written about many times before and not being a fan of such 'goodies' I consigned the scribblings to the recycling bin next to my desk and got on with my day.

Now comes the fun part wouldn't you know it I had to write a little code to print out something like this

Invoice IDs: 123747 2929 929283 kk3333

I had at my fingertips this method '$self->invoice_links' which returned an array so I came up with this


my @invoices = $self->invoice_links;
print "Invoice IDs: @invoicest";

ok easy enough but then I remembered that crumpled piece of paper soon to be on its way to the green-depot.

A little digging (realy did have to dig as it was at the bottom of the bin) and another review of my jottings and I spotted this gem @{[]}

and now I have this


print "Invoice IDs: @{[$self->invoice_links]}";

and still get this

Invoice IDs: 123747 2929 929283 kk3333

Well I think it works by calling the returned array in scalar context which is what I want here. Anyway make the code a little easier on the eyes and gets rid of a variable.

So that crumpled piece of paper is out of the bin and back into the notes binder for future use.

*well at least with the perl I ran it on. Results may vary. Do not take internally. If rash continues after 5 days consult a Doctor

1 Comment

Here's another for your notes binder:
perlsecret

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations