Simple Perl question

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Perl question
# 1  
Old 02-12-2014
Simple Perl question


I'm completely new to Perl and I'm just looking for a quick answer to some code I'm trying to come up with. I'm trying to access a website, part of the URL I want the user to be able to define via standard input. As you can see below I'm still trying to get the syntax.

HTML Code:
use warnings;
use LWP::Simple;

my site = <>;
getprint('$site') or die 'Unable to get page';

exit 0;
I'm borrowing the above code from another website. It works if I hardcode the URL rather than using a variable called site. I'm guessing the solution is simple. I appreciate the help. Yes I did search past threads for the answer.
# 2  
Old 02-12-2014
If you used "use strict;", Perl would tell you what is wrong:
No such class site at ./ line 6, near "my site"
syntax error at ./ line 6, near "my site ="
Execution of ./ aborted due to compilation errors.

Scalar variables in Perl start with "$", so correct code could look something like this:
use strict;
use warnings;
use LWP::Simple;

chomp(my $site = <>);
getprint("$site") or die "Unable to get page:$site";

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 02-12-2014
Worked like charm. Sorry for the newbie post, I promise I learn more before next time. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

2. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

3. Shell Programming and Scripting

Simple Question about Reading file by Perl

Hi , I just write a simple function to read the file line by line. But when I run it it says out of memory. I am not sure about the root cause, Can someone help me out of this? :D #! /usr/bin/perl use strict; sub checkAPs{ my $NDPDir = "/home/eweiqqu/NCB/NDP_files/"; ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

4. Shell Programming and Scripting

Simple perl question

I am totally new to perl. I am modifying someone else's script. I have the following output: # ./some-perlscript A B C D E B - E, is generated through the print command that I put in the script. I want to remove A, it seems it is generated automatically by a custom OS it is querying when... (3 Replies)
Discussion started by: streetfighter2
3 Replies

5. Shell Programming and Scripting

PERL: simple comparing arrays question

Hi there, i have been trying different methods and i wonder if somebody could explain to me how i would perform a comparison on two arrays for example my @array1 = ("gary" ,"peter", "paul"); my @array2 = ("gary" ,"peter", "joe"); I have two arrays above, and i want to something like this... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

6. Shell Programming and Scripting

perl: simple question on string append

I want to append a decimal number to a string. But I want to restrict the number to only 2 decimal points for e.g: my $output = "\n The number is = "; my $number = 2.3333333; $output = $output . $number; But I want the $output as: "The number is = 2.33"; and not 2.3333333 (I do not... (1 Reply)
Discussion started by: the_learner
1 Replies

7. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

8. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

9. UNIX for Dummies Questions & Answers

Simple question

I am taking an intro to unix class and I can not figure out how to do part of the question. I am writing script to be exictued by a program in the tutoral. Question: Write every line containing the word ``delete'' produced by ``man mail'' into a file called ``delete''. Hint: What does using... (1 Reply)
Discussion started by: weathergirl
1 Replies

10. UNIX for Dummies Questions & Answers

Simple Question

Hi All, I am new to UNIX Shell Scripting. I want to know what is the difference between the following two statements. if and if Thanks & Regards (3 Replies)
Discussion started by: tvkamesh
3 Replies
Login or Register to Ask a Question