Corona688's answer is pretty right, but don't forget to chomp!
chomp removes the newline character from the end of line. the line input operator includes the newline at the
end of the input. There are lots of ways to remove that newline, but
the best way is to use the "chomp" function
source: [Courses] [Perl] Part 3: User Input and "chomp"
This User Gave Thanks to pseudocoder For This Post:
I am using festival speech synthesis system and I would like to allow user input in a browser. This will be taken by a php page which is then supposed to pass the input text to a perl script. The perl script should pass this text to the festival engine by executing a unix command. this in turn... (2 Replies)
Hello,
I'm running a perl script to execute a program through my Unix command line. The program requires a user input but I want to automatically have perl input the string. Is there a way to do this?
Thanks (1 Reply)
Hi All,
Can we pass arguments while calling the perl script and as well as ask user input during execution of the script?
My program is as below:
I am passing arg1 and arg2 as argements to test.pl
]./test.pl arg1 arg2
Inside the test.pl I have :
print "Do you want a name ? (y/n) : ";... (2 Replies)
If I want all user input to start with " : " if not display error
or what I asking is how to do if statement that control a first letter of string that we want to start with. and not worry about the rest
Thank (1 Reply)
Hi, I want to list all file that match user input ( specified shell wildcard) but when I compile it dont list me
#!/usr/bin/perl -w
print "Enter Advance Search Function: ";
chomp ($func = <STDIN>);
my @files = glob("$func");
foreach my $file (@files)
{
print "$file\n";... (1 Reply)
Hi, How to create array every time user input and store user input and display all array
print " Enter input "
my @input = split(' ', $input)
chmop($input = <STDIN>;
foreach ($input)
{
@array= @input;
}
print @array"\n"; (1 Reply)
Hi,
I need to copy files from a source directory to a destination directory in unix.
I'm using the file::copy for the actual copy.
The problem is that the source and dest directories are supplied by different users, who might type the name of the directories in various combinations of lower... (6 Replies)
Hello friends . I am newbie to perl scripting but still managed to write a code but i am stuck at a place where i need help . Below is the code and can someone help me in taking user input for changing the font size for a html table .Thank you in advance
#!/bin/ksh
echo " Enter the Directory... (4 Replies)
I am creating a bash that uses perl . The below code closes before the input is entered. If I run the perl as a .pl it is fine. What am I doing wrong? Thank you :).
#!/bin/bash
cd 'C:\Users\cmccabe\Desktop\wget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv
print... (4 Replies)
My question is basically as the title says. How can I check a user inputted string is only certain characters long (for example, 3 characters long) and how do I check a user inputted string only contains certain characters (for example, it should only contain the characters 'u', 'a', 'g', and 'c')... (4 Replies)
Discussion started by: Eric1
4 Replies
LEARN ABOUT OSX
moose::meta::attribute::native::trait::string
Moose::Meta::Attribute::Native::Trait::String(3) User Contributed Perl Documentation Moose::Meta::Attribute::Native::Trait::String(3)NAME
Moose::Meta::Attribute::Native::Trait::String - Helper trait for Str attributes
VERSION
version 2.0604
SYNOPSIS
package MyHomePage;
use Moose;
has 'text' => (
traits => ['String'],
is => 'rw',
isa => 'Str',
default => q{},
handles => {
add_text => 'append',
replace_text => 'replace',
},
);
my $page = MyHomePage->new();
$page->add_text("foo"); # same as $page->text($page->text . "foo");
DESCRIPTION
This trait provides native delegation methods for strings.
DEFAULT TYPE
If you don't provide an "isa" value for your attribute, it will default to "Str".
PROVIDED METHODS
o inc
Increments the value stored in this slot using the magical string autoincrement operator. Note that Perl doesn't provide analogous
behavior in "--", so "dec" is not available. This method returns the new value.
This method does not accept any arguments.
o append($string)
Appends to the string, like ".=", and returns the new value.
This method requires a single argument.
o prepend($string)
Prepends to the string and returns the new value.
This method requires a single argument.
o replace($pattern, $replacement)
Performs a regexp substitution ("s" in perlop). There is no way to provide the "g" flag, but code references will be accepted for the
replacement, causing the regex to be modified with a single "e". "/smxi" can be applied using the "qr" operator. This method returns
the new value.
This method requires two arguments.
o match($pattern)
Runs the regex against the string and returns the matching value(s).
This method requires a single argument.
o chop
Just like "chop" in perlfunc. This method returns the chopped character.
This method does not accept any arguments.
o chomp
Just like "chomp" in perlfunc. This method returns the number of characters removed.
This method does not accept any arguments.
o clear
Sets the string to the empty string (not the value passed to "default").
This method does not have a defined return value.
This method does not accept any arguments.
o length
Just like "length" in perlfunc, returns the length of the string.
o substr
This acts just like "substr" in perlfunc. When called as a writer, it returns the substring that was replaced, just like the Perl
builtin.
This method requires at least one argument, and accepts no more than three.
BUGS
See "BUGS" in Moose for details on reporting bugs.
AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See "CABAL" in Moose and "CONTRIBUTORS" in Moose for
details.
COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc..
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.16.2 2012-09-19 Moose::Meta::Attribute::Native::Trait::String(3)