Thread: Casting in perl

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    21
    Rep Power
    0

    Casting in perl


    Hi,
    how do you cast a variable to be a number or integer?

    Thanks for your assistance,
    Ben
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    There's no such thing as casting in Perl. Scalar variables can hold numbers, strings or references and Perl will figure out which it's supposed to be based on the context it's used in.

    If you give an example of what you're trying to achieve, maybe we can help better.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    21
    Rep Power
    0
    Originally Posted by ishnid
    There's no such thing as casting in Perl. Scalar variables can hold numbers, strings or references and Perl will figure out which it's supposed to be based on the context it's used in.

    If you give an example of what you're trying to achieve, maybe we can help better.
    I'm trying to calculate the cost of a plant as part of a script.

    Code:
    #!c:/perl/bin/perl.exe
    
    $q=new CGI;
    use CGI ":standard";
    
    $name           =param("Name");
    $email          =param("Email");
    $telephone      =param("Telephone");
    $address        =param("Address");
    $contactMethod  =param("Contact_method");
    $salvia_splendens=param("salvia_splendens");
    $salvia_splendens_price=2;
    
    print $q->header();
    #print $q-start_html(-title=>'Enquiry Results');
    print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
    print "<HTML><HEAD><TITLE>Enquiry Results</TITLE></HEAD>\n";
    print "<BODY>";
    print "<FONT SIZE=\"4\"><B>Please confirm your details</FONT></B>";
    print "<TABLE BORDER=\"0\" WIDTH=\"500\">";
    print "<TR><TD>Name:</TD><TD>$name</TD></TR>";
    print "<TR><TD>Email Address:</TD><TD>$email</TD></TR>";
    print "<TR><TD>Telephone Number:</TD><TD>$telephone</TD></TR>";
    print "<TR><TD>Address:</TD><TD>$address</TD></TR>";
    print "<TR><TD>Salvia Splendens</TD><TD>$salvia_splendens*$salvia_splendens_price</TD></TR>";
    print "</TABLE>";
    
    print "Full information will be sent to you via $contactMethod";
    
    
    print "</BODY></HTML>";
    It treats it as a string for some reason.
  6. #4
  7. the one
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    .hr
    Posts
    109
    Rep Power
    22
    Because it is inside of " "

    This might work:
    print "<TR><TD>Salvia Splendens</TD><TD>" . $salvia_splendens*$salvia_splendens_price . "</TD></TR>";

    p.s.
    take a look of HTML::template at cpan.org - you wont regret it ;)
    http://cpan.uwinnipeg.ca/htdocs/HTML-Template/HTML/Template.html

    Comments on this post

    • ishnid agrees
    If I'm posting problem here, it means that I have not been sleeping for at least 20 hours

IMN logo majestic logo threadwatch logo seochat tools logo