Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

using a variable as the name for an array ex: @$var

iavett00iavett00 Member Posts: 3
Hello everyone,

I was wondering if anyone has ran into this problem before.

I'm passing a name to a function and then I want to create an array with that name.

something like:

sub fn {
$temp = @_[0];
@$temp[0] = "blah";
}

It doesn't want to let me do this, any advice, ideas, suggestions?

Thanks alot.

Isaac Vetter
Centre College

Comments

  • heeroyuyheeroyuy Member Posts: 125
    : Hello everyone,
    :
    : I was wondering if anyone has ran into this problem before.
    :
    : I'm passing a name to a function and then I want to create an array with that name.
    :
    : something like:
    :
    : sub fn {
    : $temp = @_[0];
    : @$temp[0] = "blah";
    : }
    :
    : It doesn't want to let me do this, any advice, ideas, suggestions?
    :
    : Thanks alot.
    :
    : Isaac Vetter
    : Centre College
    :

    Use an eval block
    -----------------------
    [RED]Heero Yuy
    Perl Board Moderator
    Perl Semi-Expert[/RED]

  • XfactorXfactor Member Posts: 343
    : Hello everyone,
    :
    : I was wondering if anyone has ran into this problem before.
    :
    : I'm passing a name to a function and then I want to create an array with that name.
    :
    : something like:
    :
    : sub fn {
    : $temp = @_[0];
    : @$temp[0] = "blah";
    : }
    :
    : It doesn't want to let me do this, any advice, ideas, suggestions?
    :
    : Thanks alot.
    :
    : Isaac Vetter
    : Centre College
    :
    I'm not familiar with have the '@' and '$' in front of the variable but that doesn't mean much. Make sure this is what you want to do. If not, and you are wanting to assign to the first element of an array, then this should be ok:
    $temp[0] = "whatever";

    $temp[0] and $temp are 2 different variables in Perl.

    X
  • Justin BibJustin Bib USAMember Posts: 0

    // http://forcoder.org // free ebooks and video tutorials about || PL/SQL JavaScript Objective-C Scratch Assembly C# Java MATLAB C++ PHP Delphi R Python C Visual Basic Swift Go Ruby Perl Visual Basic .NET Lisp Transact-SQL D Apex Rust COBOL Prolog Fortran Ada ML Lua Kotlin FoxPro Crystal Bash VBScript Logo LabVIEW Awk Clojure Scheme Hack ABAP Alice F# Erlang Julia SAS Dart Scala ||

Sign In or Register to comment.