It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I need to call a perl script from another script. The constraint is that, few global variables defined in a .pm file is common between the two scripts but the local variables are not shared. Please let me know how to do this
Is there any reason you cant call the code from the second script as a function from the first script? It should work as a single program and thus share global variables.
Check How do I include functions from another file in my Perl script? for the various ways to include one script into another.
It depends how you want this to work.
If you want to share global variables between processes then you are in for a "treat". You will need something like shared-memory (shmget) or some other IPC (Inter-Process Communication) mechanism, see perldoc perlipc. The fun part is is synchronising the two processes so they don't try to update the same thing at the same time. You really don't want to go there if you can avoid it.
Simpler is if you just want to pass those global values to the second process so it can take its own copy. If the values are simple text then you can just pass them as command-line parameters (read them from #ARGV) or as environment variables (%ENV). However, if they are more exotic, like references or file handles, then you need to figure out a different protocol. Creating the child process using fork (you might not need exec) might be a simpler way to go assuming you are not using Windows.
Better yet, consider if you really do need to copy or share those globals.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How do I properly setup my arguments if my program's name is Test.exe using the code below? I'm thinking that I need to add arguments to check for | command, but I don't need to do this if I use the redirect command ">". So I think I need to use a Stream reader in c++ but am not 100% sure how to implement it for any number of lines piped in:
using namespace System;
using namespace System::IO;
int main(array<System::String ^> ^args)
{
// this doesn't work with piped in text
Console::WriteLine(":::{0}:::", args[0]);
}
At the command prompt I type "test a" and hit enter.
:::a:::
At the command prompt I type "echo hello world | test "
:::hello world:::
An example of how this is implemented at the Windows Command prompt is with the find command. I'm trying to implement this in my c++/cli program using Visual Studio 2012. Example: "help find":
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
Your program doesn't see the pipe. The pipe is something that the shell uses to redirect stdout from the first program to the stdin of the second program. This means in Test.exe, you'll get the input by using Console::Readline:
Console::WriteLine(":::{0}:::", Console::ReadLine());
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have one module, such as A.pm, in this A.pm, it will read and write one certain conf file, such A.conf.
Now in my perl script file: 1_perl.pl, I use A.pm to reset certain value in A.conf file and also use A.pm to write this value in 2_perl.pl. So my question is how to hand this process in background? It will produce 2 A.pm instance to handle this or just one instance ?
Please give more details about this , thank you in advance
Perl modules are just loadable blobs of functions and data -- modules are not processes, so your question doesn't really make sense.
If you want your module to create a background process to write out the configuration file, that's certainly doable, but you'll have to implement it yourself. Deciding how to manage these processes is up to you.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I use the examples from the CoffeeScript homepage and it doesn't validate.
The for loop one is a perfect example, if you use the coffeescript statement it doesn't wrap the body in an if statement.
Expected '{' and instead saw 'child'.
Possible strict violation.
A constructor name should start with an uppercase letter.
'insertclassnamehere' is already defined.
Did you mean to return a conditional instead of an assignment?
Expected '===' and instead saw '=='.
Unexpected '~'.
Expected '!==' and instead saw '!='.
The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.
My compiled CoffeeScript won't validate in JShint .. why?
The short answer would be: Because the creators of the CoffeeScript compiler didn't deem it necessary.
It makes sense to lint code which is written and maintained by developers. It avoids human errors by making code readable.
The code generated by a compiler on the other hand has completely different requirements. Readability is usually not a concern. It's more important that the code is efficient and small.
If you really want this then you need to modify the CoffeeScript compiler source.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have shell scripting knowledge.
I have written a small shell script which will take a single argument.
with the help of that argument.
the file name format is axeA10_<date_time_stamp>_<sequence_number>.DAT
my script just takes all the files in the current directory and changes the sequence number.
so that i have the files with sequence numbers.
the need to write this script is that i dont have the files with the sequence number as some of the sequences are missing.
I know that perl can be more fast in doing this kind of tasks.And so i want to learn the same.
Can anyone convert this small shell script to perl.this would really boost my confidence in learning perl.Thanks in advance.Below is the script which works fine.
#!/bin/ksh
counter=1
for i in ${1}*.DAT
do
if [ $counter -lt 10 ]
then
new_name=`echo "$i"|awk -vcount=$counter 'BEGIN{FS="_";OFS="_"}{$3=count}{print $1"_"$2"_0"$3".DAT"}'`
else
new_name=`echo "$i"|awk -vcount=$counter 'BEGIN{FS="_";OFS="_"}{$3=count}{print $0".DAT"}'`
fi
mv $i $new_name
counter=$(($counter+1))
done
exit
"Can anyone convert this small shell script to perl.this would really boost my confidence in learning perl."
How would someone doing this for you boost your confidence?
Visit the following URL
http://learn.perl.org/
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How to parse the string's individual character for eg " =-. lajadsfdddll ooo532333 ksfoiww0etu - " /.> W#H^*!##~ nsa#". and add each individual character into hash and then count as ohw many times each character has apeared and the only unique character.
As it sounds very much like a homework question, I'll try pushing you in the right direction. Hopefully you know how to take in a line of user input. In this case, your very general algorithm will look like this:
1. Take the input
2. Parse the input into individual characters - Think about Perl built in methods
3. Add characters to the Hash and count.
4. Iterate through the Hash and print the relevant data.
Character counting is a pretty common problem in a variety of languages, so utilizing Google will be your friend. Also consider that Hashes associate a Key with some value, and only stores unique keys, but it can store any value type.
Additionally, the Perl Cookbook has a recipe on the free online book that discusses how to read individual characters of a string, and this tutorial can be found in a variety different sites.
Long story short, there are plenty of resources out there to answer this problem, and you'll learn more if you go out and find them.