Hi all,

I'm currently attempting to piece together a program that will generate a URL I need, drawing on a list of serial numbers from a DB. Thing is, the list of serial numbers needs to be comma separated, which would be easy enough with join(",", @array). Alas, no matter where I attempt said join, Perl laughs at me and produces the list of undelimited serial numbers.

The code I have so far:
my $ref = $sth->fetchall_arrayref(); foreach my $result (@$ref) { $sn .= $result->[0]; } return $sn; $sth->finish(); $dbh->disconnect();
The desired result, when paired with the first part of the URL, would be XXXX-XXXX,XXXX-XXXX, not the XXXX-XXXXXXXX-XXXX I am left with.

I've tried this on a while() loop using $sth->fetch_array(), pre-declaring the array and trying to join it. I knew it was empty and I knew it wouldn't work, but then I've never mastered the art of thinking things through. I've also tried applying the join() inside of the loop, or applying to the LHS and RHS of my $sn .= $result[0] / $result->[0], neither of which worked either.

Anyway, the program in its incomplete entirety:
#!/us/bin/perl + + + use strict; use warnings; use DBI; use LWP::UserAgent; sub get_serialno { my $dbh = DBI->connect("DBI:mysql:database=stuff;host=localhost", "w +oo", "hoo", {'RaiseError' => 1}) || die "Error: " . DBI->errstr; my $sth = $dbh->prepare("SELECT serialno FROM appliances"); $sth->execute(); my $sn; my $ref = $sth->fetchall_arrayref(); foreach my $result (@$ref) { $sn .= $result->[0]; } return $sn; $sth->finish(); $dbh->disconnect(); } my $asyncos = shift || die "Usage: imagefetch.pl <version number>-<bui +ld>\n"; my ($version, $build) = split /-/, $asyncos; (my $mversion = $version) =~ s/\./-/g; my $urlpart = "http://downloads.ironport.com/asyncos/upgrade/asyncos-$ +mversion.ipup?requested_version=phoebe-$mversion-$build&serial="; my $snpart = get_serialno; my $url = $urlpart . $snpart; print $url; print "\n\n";
The LWP stuff itself will be simple. Running out of talent (or tutorials!) at a small hurdle like this is um, annoying :). A clue, a smack upside the head or a RTFM (please include a hyperlink) all welcome.

Many thanks in advance.
UPDATE: Fixed with one line of code. Must try harder next time.

In reply to Using join() on a MySQL arrayref by fivefiftyone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.