Find the answer to your Linux question:
Results 1 to 3 of 3
Please help me understanding the meaning of following in Perl Script my $type; my sth =$db->prepare($sql); my $sth->execute(); while (my $var = $sth->fetchrow_arrayref){ $type->{"@$var[0]"}=" "; }...
  1. #1
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114

    Query in PerlCGI & DBI ------ @$var[0] ???

    Please help me understanding the meaning of following in Perl Script

    my $type;
    my sth =$db->prepare($sql);

    my $sth->execute();
    while (my $var = $sth->fetchrow_arrayref){
    $type->{"@$var[0]"}=" ";
    }

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Does this code actually work?

    The reason I ask is this: $var is currently an arrayref. However, it seems like two techniques were combined here. They are dereferencing the arrayref into an array ("@$var"), but they are then taking an array index. If you wanted to take the index of an arrayref, you would usually do "$var->[0]".

    Combine that with the fact that it's wrapped in a string, and this code becomes _very_ strange.

    What are you trying to accomplish with this?
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Linux Newbie
    Join Date
    Jan 2008
    Posts
    114
    Even I am not able run the same but I don't how its working for long time.

    Following is another same kind code, have a look. If you can help me to understand.

    $sq = "select distinct date from sr_stats";

    $sth = $db->prepare($sq) or die "Cannot prepare: " . $db-errstr();

    $sth->execute() or die "Cannot execute: " . $sth->errstr();

    while (my $var = $sth->fetchrow_arrayref) {
    $dates->{"@$var[0]"}=" ";
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...