Sponsored Content
Full Discussion: Perl newbie questions!
Top Forums Shell Programming and Scripting Perl newbie questions! Post 302323421 by byte1918 on Sunday 7th of June 2009 04:24:12 PM
Old 06-07-2009
Quote:
Originally Posted by KevinADC
Code:
#!C:\Perl64\bin\perl.exe -w
print "Content-Type: Text/plain\n\n";#<-- this is not necessary unless running as a CGI script

@horse = ("mdamdamad" , "asdasda" ,"asdasd" ,"a");

getindex ("asd",@horse);

sub getindex {
   ($string,@a) = @_;
   print $string."\n";
   foreach $key (@a){
      print $key."\n";
   }
}

You're going to want to learn how to use references in perl really quickly insterad of trying to pass mixed data types like int he code above. An example:

Code:
#!C:\Perl64\bin\perl.exe -w
print "Content-Type: Text/plain\n\n";

@horse = ("mdamdamad" , "asdasda" ,"asdasd" ,"a");

getindex ("asd",\@horse);

sub getindex {
   my ($string,$array_ref) = @_;
   print $string."\n";
   foreach $key (@{$array_ref}){
      print $key."\n";
   }
}

The first three tutorials on this page discuss references:

Tutorials - perldoc.perl.org

Also:

you will want to use "warnings" and "strict" pragmas and start declaring your variables properly when writing perl code.

Code:
#!C:\Perl64\bin\perl.exe
use warnings;
use strict;
print "Content-Type: Text/plain\n\n";

my @horse = ("mdamdamad" , "asdasda" ,"asdasd" ,"a");

getindex ("asd",\@horse);

sub getindex {
   my ($string, $array_ref) = @_;
   print $string."\n";
   foreach $key (@{$array_ref}){
      print $key."\n";
   }
}

Also, don't use $a and $b as private variables in your perl scripts. Perl uses them for sorting data.

The http header was also wrong, you had: Text-plain should be: Text/plain
thanks alot KevinADC your response was very helpful! Smilie
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

A few newbie questions

Hi :) I just wanted to ask a few basic questions really. I'm telnetting to a remote host and I've finally found out that I'm using a csh shell. My questions are: 1. Is the somename@something, the user group logged in? 2. How do I change user? I'm really lost so I hope someone can help... (7 Replies)
Discussion started by: hellz
7 Replies

2. UNIX for Dummies Questions & Answers

buncha questions from a newbie

Even though I have been logging in to a UNIX shell at school to complete school projects and write programs, but I had never really worked in UNIX environment. But a couple of weeks back I got hooked on to Solaris 9OE, read a book, a tutorial, a document provided on the Sun Microsystems website,... (1 Reply)
Discussion started by: init-5
1 Replies

3. Linux

newbie questions on ntp and routes

RH 7.2 I have 2 unrelated questions - 1.) I have been able to configure and run ntp but cannot figure out how to start the service upon reboot. I have read the man pages for ntsysv - this is a manual action, but I want to drop a tarball of config files on a new installation and cannot... (1 Reply)
Discussion started by: jalburger
1 Replies

4. Shell Programming and Scripting

Newbie Questions

I am relatively new to both KSH and Unix scripting, and I would like some help getting my script up and running. I would like to have the script attempt various commands (tar, copy, gzip etc) and then write the results (error msg or success msg) to a temp file. I would then like an email sent to... (2 Replies)
Discussion started by: mharley
2 Replies

5. Linux

Questions of a newbie

I have been an apple customer for years now, and am not satisfied with the direction that they are going. So I just ordered my first PC notebook the other day. I have no desire to use windows, however with microsoft's hold on the market, I feel that I may have a hard time doing this. I want to... (2 Replies)
Discussion started by: Brycemb16
2 Replies

6. UNIX for Dummies Questions & Answers

unix questions for newbie

Hi Unix gurus, I know these are some easy questions. But i just want to be sure about them. Hope someone can help explain the following please? 1) if ] - What does the "-r" means? 2) isql -U $DBUSER -D $DBNAME -S $DSQUERY -w 1000 -s";" << testfile > $FILE - What does the -s";" mean and... (1 Reply)
Discussion started by: gholdbhurg
1 Replies

7. UNIX for Dummies Questions & Answers

LISP newbie's questions

Hello, I want to learn LISP, and I have a GNU/Linux OS. I first sought a LISP compiler/interpreter and was told that GNU Emacs has a LISP mode. But I couldn't get into LISP mode, nor I don't know how to use it when I get into LISP mode. How can I run LISP code under GNU Emacs? And if... (1 Reply)
Discussion started by: rayne
1 Replies

8. Solaris

Solaris Newbie questions...

Hello everyone, I am brand spanking new to both Solaris and Unix. I thought I would give it a go after buying a SB2500 off ebay for a few hundred dollars. I am having some issues that I am not sure how to correct, and I am wondering if I can get a few pointers? The first one is that my system... (2 Replies)
Discussion started by: GeekMasterFlash
2 Replies

9. AIX

Newbie Questions for AIX !!!

Hi Guys, I am new in this forum and new with AIX however not new with Power System. I have worked with iSeries for many years. Now supporting AIX on Power. Here are some basic questions I have. 1. I am using Putty to connect from my PC to the AIX boxes. Is there any other (better) program to... (6 Replies)
Discussion started by: 300zxmuro
6 Replies
Mojo::Content::Single(3pm)				User Contributed Perl Documentation				Mojo::Content::Single(3pm)

NAME
Mojo::Content::Single - HTTP 1.1 content container SYNOPSIS
use Mojo::Content::Single; my $single = Mojo::Content::Single->new; $single->parse("Content-Length: 12 Hello World!"); DESCRIPTION
Mojo::Content::Single is a container for HTTP 1.1 content as described in RFC 2616. EVENTS
Mojo::Content::Single inherits all events from Mojo::Content and can emit the following new ones. "upgrade" $single->on(upgrade => sub { my ($single, $multi) = @_; ... }); Emitted when content gets upgraded to a Mojo::Content::MultiPart object. $single->on(upgrade => sub { my ($single, $multi) = @_; return unless $multi->headers->content_type =~ /multipart/([^;]+)/i; say "Multipart: $1"; }); ATTRIBUTES
Mojo::Content::Single inherits all attributes from Mojo::Content and implements the following new ones. "asset" my $asset = $single->asset; $single = $single->asset(Mojo::Asset::Memory->new); The actual content, defaults to a Mojo::Asset::Memory object with "auto_upgrade" enabled. "auto_upgrade" my $upgrade = $single->auto_upgrade; $single = $single->auto_upgrade(0); Try to detect multipart content and automatically upgrade to a Mojo::Content::MultiPart object, defaults to 1. METHODS
Mojo::Content::Single inherits all methods from Mojo::Content and implements the following new ones. "new" my $single = Mojo::Content::Single->new; Construct a new Mojo::Content::Single object and subscribe to "read" event with default content parser. "body_contains" my $success = $single->body_contains('1234567'); Check if content contains a specific string. "body_size" my $size = $single->body_size; Content size in bytes. "clone" my $clone = $single->clone; Clone content if possible, otherwise return "undef". "get_body_chunk" my $chunk = $single->get_body_chunk(0); Get a chunk of content starting from a specfic position. "parse" $single = $single->parse("Content-Length: 12 Hello World!"); my $multi = $single->parse("Content-Type: multipart/form-data "); Parse content chunk and upgrade to Mojo::Content::MultiPart object if possible. SEE ALSO
Mojolicious, Mojolicious::Guides, <http://mojolicio.us>. perl v5.14.2 2012-09-05 Mojo::Content::Single(3pm)
All times are GMT -4. The time now is 09:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy